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 difference between a max heap and a min heap?
A max heap has the largest element at the root, with each parent node greater than or equal to its children. A min heap has the smallest element at the root, with each parent node less than or equal to its children.
Click to reveal answer
intermediate
How is a heap usually represented in memory?
A heap is usually represented as an array where the parent and child relationships are determined by indices: for a node at index i, its left child is at 2i + 1, and its right child is at 2i + 2.
Click to reveal answer
beginner
What is the heap property?
The heap property ensures that in a max heap, every parent node is greater than or equal to its children, and in a min heap, every parent node is less than or equal to its children. This property must hold for all nodes except leaves.
Click to reveal answer
intermediate
Why is a heap considered a complete binary tree?
A heap is a complete binary tree because all levels are fully filled except possibly the last level, which is filled from left to right without gaps. This structure allows efficient storage in arrays.
Click to reveal answer
In a max heap, where is the largest element located?
✗ Incorrect
In a max heap, the largest element is always at the root node because every parent is greater than or equal to its children.
How do you find the left child index of a node at index i in a heap array?
✗ Incorrect
The left child of a node at index i is at index 2 * i + 1 in the array representation of a heap.
What type of tree structure is a heap?
✗ Incorrect
A heap is a complete binary tree, meaning all levels are fully filled except possibly the last, which is filled from left to right.
Which property must a min heap satisfy?
✗ Incorrect
In a min heap, every parent node is less than or equal to its children, ensuring the smallest element is at the root.
Why is a heap efficient for implementing priority queues?
✗ Incorrect
Heaps allow quick access to the highest (max heap) or lowest (min heap) priority element at the root, making them efficient for priority queues.
Explain the structure and key properties of a heap.
Think about how the tree is filled and how parent and child values relate.
You got /3 concepts.
Describe how you can find the children and parent of a node in a heap stored as an array.
Use simple math formulas based on the node's index.
You got /3 concepts.