• Tutorials
  • Courses
  • Tracks

Quiz on Heap

Last Updated :
Discuss
Comments

Question 1

What is the time complexity of inserting an element into a max heap of size n ?

  • O(1)

  • O(log n)

  • O(n)

  • O(n*log n)

Question 2

In a max heap, for any node at index i, what is the index of its parent (1-based indexing) ?

  •  i / 2

  • (i - 1) / 2

  • 2 * i

  • i + 1

Question 3

Which of the following arrays represents a valid max heap ?

  • [90, 15, 10, 7, 12, 2, 7, 3]

  • [10, 15, 30, 40, 50]

  • [100, 19, 36, 17, 3, 25, 1, 2, 7]

  • [5, 7, 6, 8, 10]

Question 4

Suppose you have a min-heap, and the value of a node is decreased, breaking the heap property. Which operation fixes the heap?

  • Heapify-down

  • Heapify-up

  • Build Heap again

  • No operation needed

Question 5

In a min-heap, the array storing elements in level-order is:

  • Sorted in increasing order

  • Sorted in decreasing order

  • not fully sorted (Ordered only by parent-child relationships)

  • Sorted alternately min-max

Question 6

What is the height of a heap with n elements?

  • O(n)

  • O(log n)

  • O(1)

  • O(n*log n)

Question 7

Which of the following statements about a binary heap is TRUE?

  • It is always a complete binary tree

  • It is always a balanced binary search tree

  • It is always full

  • It is always sorted

Question 8

You need to find the k smallest elements in an unsorted array of size n. Which approach is optimal using a heap?

  • Build a min-heap of all elements and extract k times

  • Build a max-heap of size k

  • Use a min-priority queue to keep track of k smallest

  • Build a max-heap of all elements

Question 9

What will be the content of the max heap after inserting 40 in the heap [50, 30, 20, 15, 10] ?

  • [50, 40, 20, 30, 10, 15]

  • [50, 40, 20, 15, 10, 30]

  • [40, 50, 20, 15, 10, 30]

  • [50, 30, 40, 15, 10, 20]

Question 10

In a complete binary tree with n nodes, the number of leaf nodes is approximately:

  • n/4

  • n/2

  • n

  • log n

There are 10 questions to complete.

Take a part in the ongoing discussion