arrow
arrow
arrow
How will the following min-heap appear on inserting the key 32?
Question

How will the following min-heap appear on inserting the key 32?

A.

B.

C.

D.

None of the above

Correct option is B

A min-heap is a complete binary tree in which the key at every parent node is less than or equal to the keys of its children. The given heap contains 10 elements, so the newly inserted key 32 is first placed at the next available position to preserve the complete binary tree property.
This position is the left child of node 40. Since 32 < 40, the min-heap property is violated, so 32 is exchanged with 40. After the exchange, 32 becomes the child of node 10, and since 32 > 10, no further upward adjustment is required.
Therefore, the resulting heap is exactly Option (b).
Information Booster
1. Initial heap in level-order: 5, 10, 25, 30, 40, 50, 60, 70, 80, 90
2. Insertion position of 32
· A heap must always remain a complete binary tree.
· Therefore, 32 is initially inserted at the 11th position in level-order.
· Its parent is the node 40.
3. Heapify-up operation
· Since 32 < 40, the newly inserted element violates the min-heap property.
· Interchange 32 and 40.
· The relevant portion becomes:
10 → 32 → 40
4. Final check
· The parent of 32 is now 10.
· Since, 10 < 32 the min-heap property is satisfied.
· Hence, no further swapping is necessary.
5. Final level-order representation:
5, 10, 25, 30, 32, 50, 60, 70, 80, 90, 40
Additional Knowledge
· Option (a) is incorrect: It places 32 as a child of 40 without performing the required upward adjustment. Since 32 < 40, that configuration violates the min-heap property.
· Option (c) is incorrect: Its structure does not represent the correct result of inserting 32 into the given complete binary tree. In particular, the positions of several existing elements are changed unnecessarily.
· Important point: During insertion into a min-heap, the new element is always placed at the next available leaf position first, followed by heapify-up (sift-up) until the heap property is restored.
· For a heap containing n elements, insertion takes O(log n) time in the worst case because the newly inserted element can move upward by at most the height of the heap.

Free Tests

Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English
Free
Must Attempt

UGC NET Paper 1 Mock Test 1

languageIcon English
  • pdpQsnIcon50 Questions
  • pdpsheetsIcon100 Marks
  • timerIcon60 Mins
languageIcon English
Free
Must Attempt

Basics of Education: Pedagogy, Andragogy, and Hutagogy

languageIcon English
  • pdpQsnIcon10 Questions
  • pdpsheetsIcon20 Marks
  • timerIcon12 Mins
languageIcon English

Similar Questions

test-prime-package

Access ‘UGC NET Computer Science’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
527k+ students have already unlocked exclusive benefits with Test Prime!

Similar Questions

Our Plans
Monthsup-arrow