You know from the lectures that a heap can be built from an array of integers in time. Heap is ordered such that each parent node has a key that is bigger than both children's keys. So it seems like we can sort an array of arbitrary integers in time by building a heap from it. Is it true?
Correct! Although the key of each parent node is bigger than the keys of the children, the keys can be not ordered from the biggest to the smallest. For example, with just three numbers the head element is bigger than both children and , but their relative order is wrong. Also, you should recall from the Algorithmic Toolbox class that it is impossible to sort objects based only on results of comparisons of pairs of objects faster than in time.
You've organized a party, and your new robot is going to meet and greet the guests. However, you need to program your robot to specify in which order to greet the guests. Of course, guests who came earlier should be greeted before those who came later. If several guests came at the same time or together, however, you want to greet first the older guests to show them your respect. You want to use a min-heap in the program to determine which guest to greet next. What should be the comparison operator of the min-heap in this case?
Correct! If the guests come at different times, the one who came earlier will be greeted before. If the guests came at the same time, the older one will be greeted earlier.
You want to implement a Disjoint Set Union data structure using both path compression and rank heuristics. You also want to store the size of each set to retrieve it in . To do this, you've already created a class to store the nodes of DSU and implemented the method using the path compression heuristic. You now need to implement the method which will both use rank heuristics and update the size of the set. Which one is the correct implementation?
Correct! You need to determine the new root using the rank heuristics, and then not forget to update the size stored in the new root.