Challenge - 5 Problems
Heap Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this min-heap insertion sequence?
Consider an empty min-heap. Insert the elements in this order: 10, 4, 15, 20, 0. What is the heap array after all insertions?
DSA C
Insert 10 Insert 4 Insert 15 Insert 20 Insert 0 Print heap array
Attempts:
2 left
💡 Hint
Remember min-heap keeps smallest element at root and maintains heap property after each insertion.
✗ Incorrect
After inserting 10, heap is [10]. Insert 4, swap with 10 → [4,10]. Insert 15 → [4,10,15]. Insert 20 → [4,10,15,20]. Insert 0, bubble up to root → [0,4,15,20,10].
🧠 Conceptual
intermediateWhich property must a max-heap always satisfy?
Choose the correct property that a max-heap must always satisfy.
Attempts:
2 left
💡 Hint
Think about what 'max' means in max-heap.
✗ Incorrect
In a max-heap, each parent node must be greater than or equal to its children to keep the maximum element at the root.
🔧 Debug
advancedWhat error occurs when trying to insert into a full fixed-size heap array?
Given a fixed-size array representing a heap with capacity 5, what happens if you try to insert a 6th element?
DSA C
int heap[5]; int size = 5; // heap is full insert(heap, size, 10);
Attempts:
2 left
💡 Hint
Think about what happens when you access beyond array limits.
✗ Incorrect
Trying to insert beyond the fixed array size causes an out-of-bounds error because the array cannot hold more elements.
❓ Predict Output
advancedWhat is the heap array after extracting the root from this max-heap?
Given max-heap array: [20, 15, 18, 8, 10, 5]. After extracting the root (20), what is the resulting heap array?
DSA C
Extract root from max-heap [20, 15, 18, 8, 10, 5] Reheapify
Attempts:
2 left
💡 Hint
After removing root, replace with last element and heapify down.
✗ Incorrect
Remove 20, replace root with 5 → [5,15,18,8,10]. Heapify down swaps 5 with 18 → [18,15,5,8,10]. 5 now has no children, so heapify stops.
🧠 Conceptual
expertWhat is the time complexity of building a heap from an unsorted array of n elements?
Choose the correct time complexity for building a heap from an unsorted array of size n.
Attempts:
2 left
💡 Hint
Heapify process is more efficient than inserting elements one by one.
✗ Incorrect
Building a heap using the bottom-up heapify method runs in linear time O(n), not O(n log n).
