0
0
DSA Typescriptprogramming~5 mins

Heap Concept Structure and Properties in DSA Typescript - 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 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?
AAt any random node
BAt the root node
CAt the rightmost leaf
DAt the leftmost leaf
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 type of tree structure is a heap?
APerfect binary tree
BFull binary tree
CComplete binary tree
DBinary search tree
Which property must a min heap satisfy?
AParent nodes are less than or equal to their children
BParent nodes are greater than their children
CAll leaf nodes are greater than root
DChildren nodes are always equal
Why is a heap efficient for implementing priority queues?
ABecause it uses linked lists internally
BBecause it stores elements in sorted order
CBecause it has no structure
DBecause it allows quick access to the highest or lowest priority element
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.