ProgrammingModerateProduct-company MCQ pattern

Which statement about the heapq module is correct?

  1. A. heapq implements a max-heap, so heap[0] is the largest item
  2. B. heapq.heappop returns the largest item in the heap
  3. C. heapq implements a min-heap, so heap[0] is the smallest item
  4. D. heapq keeps the whole list sorted after every push

Correct answer: C. heapq implements a min-heap, so heap[0] is the smallest item

heapq maintains the heap invariant, so the smallest item is always at index 0 and heappop removes it. The list is not fully sorted, and heappop returns the smallest item.

More Python Programming questions

Exams that ask this topic