🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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 →
  1. Q1. In the array form of a heap, what are the children of the node at index 4?
  2. Q2. What is the parent index of the node at index 6?
  3. Q3. What does this print? (code)
  4. Q4. A new value is pushed onto a min-heap. Where is it placed first, and which way does it move?
  5. Q5. During sift down in a min-heap, the node is swapped with:
  6. Q6. Why does heapify (sifting down from the last parent to the root) take O(n) and not O(n log n)?
  7. Q7. What does this print? (code)
  8. Q8. Which statement about heap sort is true?
  9. Q9. To find the 10 largest values in a stream of a million numbers, the best heap approach is:
  10. Q10. In Java, what does new PriorityQueue<(Collections.reverseOrder()) give you?
  11. Q11. What does this print? (code)
  12. Q12. Is the array [1, 3, 2, 7, 4, 5] a valid min-heap?
  13. Q13. What does this print? (code)
  14. Q14. How do you use Python's heapq as a max-heap of numbers?
  15. Q15. What is the time to pop the smallest item from a binary heap of n items?