I have a C ++ assignment where I have to develop a naive solution to Knut's problem with the container of my choice and study the generated performance data. See Problem below:
Three million men with different names were laid in the end, reaching from New York to California. Each participant was delivered a sheet of paper on which he wrote down his name and the name of the person, directly to the west of him on the line. The man at the extreme western end of the line did not understand what to do, so he threw away his newspaper; the remaining 2,999,999 sheets of paper were placed in a huge basket and delivered to the National Archives in Washington, DC. The contents of the basket were completely shuffled and transferred to magnetic tapes.
At this point, an informant scientist noticed that the tapes had enough information about restoring the list of people in their original order. And a computer scientist discovered a way to make a reconstruction with less than 1000 passes on data tapes, using only sequential access to the tapes and a small amount of random access memory. How is this possible?
[In other words, given the pairs (xi, xi + 1) for 1 ≤ i <N, in random order, where xi are different, how can we get the sequence x1 x2 .... xN, restricting all operations to sequential methods suitable for use on magnetic tapes. This is the problem of sorting in order, when there is no easy way to determine which of the two given keys precedes the other,
unordered_map, . , , - , :
(Name, Name) , ( ), ( ) .
- identify an individual xc
- append xc to empty list
- while xc has westerly neighbour
- xc < westerly neighbour of xc
- append xc to list
- xc < head of list
- while xc has easterly neighbour
- xc < easterly neighbour of xc
- prepend xc to list
- xc , - ?
- , , :
Hazbgaei,Ckwkkkxa
Hrunmkoc,Usjgmunt
Cmkcwncb,Ycrnwzjl
Oygvmrhf,Hylmukiw
Jursaual,Gzrddsbg
, , , , ?
, , !