0
0
DSA Javascriptprogramming~5 mins

Heap Concept Structure and Properties in DSA Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ABalance property
BHeap property
CShape property
DOrdering property
In a max heap, what is true about the parent node compared to its children?
AParent is smaller than children
BParent is equal or greater than children
CParent is always equal to children
DParent is unrelated to children
How do you find the left child index of a node at index i in a heap array?
A2 * i + 1
B2 * i
Ci / 2
Di - 1
What is the time complexity to insert an element into a heap?
AO(log n)
BO(n)
CO(1)
DO(n log n)
Which of these is NOT true about heaps?
AHeaps are complete binary trees
BHeaps can be efficiently stored in arrays
CHeaps allow quick access to max or min element
DHeaps maintain a strict ordering between siblings
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.