Recall & Review
beginner
Why do we need a heap when we already have a sorted array?
A heap allows faster insertion and deletion of the smallest or largest element compared to a sorted array, which requires shifting many elements.
Click to reveal answer
beginner
What is the main inefficiency of a sorted array when inserting a new element?
Inserting a new element in a sorted array requires shifting elements to keep order, which takes O(n) time.
Click to reveal answer
intermediate
How does a heap improve deletion of the smallest or largest element compared to a sorted array?
A heap can remove the smallest or largest element in O(log n) time by reorganizing the tree, while a sorted array takes O(n) due to shifting elements.
Click to reveal answer
intermediate
What operation is very fast in a sorted array but slower in a heap?
Accessing the smallest or largest element is O(1) in a sorted array and O(1) in a heap as well; however, sorted array has slower insertion and deletion.
Click to reveal answer
beginner
Explain in simple terms why heaps are useful for priority queues.
Heaps let us quickly add new items and remove the highest priority item without sorting everything again, making them perfect for priority queues.Click to reveal answer
What is the time complexity of inserting an element into a sorted array?
✗ Incorrect
Inserting into a sorted array requires shifting elements to keep order, which takes O(n) time.
Which data structure allows faster removal of the smallest element?
✗ Incorrect
Heap removes the smallest element in O(log n) time, faster than a sorted array's O(n) due to shifting.
Why is a heap preferred over a sorted array for priority queues?
✗ Incorrect
Heaps allow fast insertion and removal of highest priority elements without full sorting.
What is the time complexity of removing the smallest element from a heap?
✗ Incorrect
Removing the smallest element from a heap takes O(log n) time due to reheapification.
Which operation is fastest in a sorted array compared to a heap?
✗ Incorrect
Accessing the smallest element is O(1) in a sorted array because it is at a known position.
Explain why heaps exist and what problems they solve that sorted arrays cannot handle efficiently.
Think about how adding or removing elements affects order and speed.
You got /4 concepts.
Describe the main differences in performance between heaps and sorted arrays for insertion and deletion operations.
Focus on how many elements need to move or be reorganized.
You got /4 concepts.