Recall & Review
beginner
What is a heap in data structures?
A heap is a special tree-based data structure that satisfies the heap property: in a max heap, every parent node is greater than or equal to its children; in a min heap, every parent node is less than or equal to its children.
Click to reveal answer
beginner
What is the shape property of a heap?
The shape property means the heap is a complete binary tree, where all levels are fully filled except possibly the last level, which is filled from left to right.
Click to reveal answer
beginner
Explain the heap property with an example.
In a max heap, if a parent node has value 10, its children must have values less than or equal to 10. For example, a parent 10 with children 8 and 5 satisfies the heap property.
Click to reveal answer
intermediate
How is a heap usually represented in memory?
A heap is often represented as an array where the parent and child relationships are determined by indices: for a node at index i, left child is at 2i + 1, right child at 2i + 2, and parent at Math.floor((i - 1) / 2).
Click to reveal answer
intermediate
Why is the heap structure useful for priority queues?
Because the heap property allows quick access to the highest (max heap) or lowest (min heap) priority element at the root, making insertion and removal operations efficient (O(log n)).
Click to reveal answer
Which property ensures that a heap is a complete binary tree?
✗ Incorrect
The shape property ensures the heap is a complete binary tree.
In a max heap, what is true about the parent node compared to its children?
✗ Incorrect
In a max heap, the parent node is always equal or greater than its children.
How do you find the left child index of a node at index i in a heap array?
✗ Incorrect
Left child index is calculated as 2 * i + 1.
What is the time complexity to insert an element into a heap?
✗ Incorrect
Insertion in a heap takes O(log n) time due to heap property restoration.
Which of these is NOT true about heaps?
✗ Incorrect
Heaps do not require ordering between siblings, only between parent and children.
Describe the two main properties of a heap and why they matter.
Think about the tree shape and the value order between nodes.
You got /4 concepts.
Explain how a heap is represented using an array and how to find parent and child nodes.
Focus on the formulas for indices.
You got /5 concepts.