21.5 Exercises
Last updated
Last updated
Represent the following heap as an array.
Consider the above heap. What range of values, when inserted, will cause the maximum number of swaps?
Consider an externally-chained hashmap. If there are many hash collisions, what data structure would be most efficient in storing the key-value pairs at each bucket?
Consider an array sorted in descending order. Is this a valid heap? If so, which type: min-heap, or max-heap?
Suppose that we store the root of a heap at the 0
th index in our array. For an arbitrary index k
, compute the indices of its children and parent.
Explain how you would implement a stack using a priority queue.