← All topics
Quiz: Heaps and Heap Sort Internals: questions with answers
15 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. In the array form of a heap, what are the children of the node at index 4?
- Q2. What is the parent index of the node at index 6?
- Q3. What does this print? (code)
- Q4. A new value is pushed onto a min-heap. Where is it placed first, and which way does it move?
- Q5. During sift down in a min-heap, the node is swapped with:
- Q6. Why does heapify (sifting down from the last parent to the root) take O(n) and not O(n log n)?
- Q7. What does this print? (code)
- Q8. Which statement about heap sort is true?
- Q9. To find the 10 largest values in a stream of a million numbers, the best heap approach is:
- Q10. In Java, what does new PriorityQueue<(Collections.reverseOrder()) give you?
- Q11. What does this print? (code)
- Q12. Is the array [1, 3, 2, 7, 4, 5] a valid min-heap?
- Q13. What does this print? (code)
- Q14. How do you use Python's heapq as a max-heap of numbers?
- Q15. What is the time to pop the smallest item from a binary heap of n items?