I am reading about multidimensional sorts in Algorithms by C++ RobertSedwick which is as below.
To handle multidimensional sorts, where the sort keys are vector and the records are to be rearranged such that the first components of the keys are in order, then those with first component equal are in order by second component, and so forth. If the components do not have duplicate kdeys, the problem reduces to sorting on first component; in a typical application, however, each of the components may have only a few distinct values, and three-way partitioning(moving to the next component for the middle partition.
My questions on above text are
- What does author mean by first component, second component?
- What does author mean by if components do not have duplicate keys the problem reduces to sorting on first component?
Thanks for your time and help
The author is describing lexicographical order of keys in a mapping. Imagine you have a list of pairs of values:
The first in each pair is being called the “first component” and the second is, of course, the “second component”. The lexicographical ordering of these items is:
How do we arrive at this? First the pairs are sorted by their first components. The first components are
4, 2, 1, 4which in order are1, 2, 4, 4. But there are two fours. We can further order them by their second components, such that(4 2)comes before(4 3).Of course, they need not be pairs. You can apply lexicographical order to elements with any number of values. They are ordered by the first component, then the second, then the third, etc.
The name of this ordering comes from how we order words in many languages. Given three names, John, Jim, and Alice, how do we order them? First we order by the first letter, then the second letter and so on. The lexicographical ordering of these names is Alice, Jim, John.
In the author’s description, this kind of ordering is being used to order the keys of a map. That is, the pairs are mapped to some value. For example, the key could be a pair and the value is a letter:
The ordering of these letters after sorting the keys lexicographically would be
C, B, D, A.