0
0
DSA C++programming~10 mins

Heap Concept Structure and Properties in DSA C++ - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a max heap using C++ STL priority_queue.

DSA C++
std::priority_queue<int> [1];
Drag options to blanks, or click blank then click option'
AmaxHeap
BminHeap
Cpq
Dheap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'minHeap' which is misleading for max heap declaration.
2fill in blank
medium

Complete the code to get the index of the left child of a node at index i in a heap array.

DSA C++
int leftChild = 2 * [1] + 1;
Drag options to blanks, or click blank then click option'
Ai
Bindex
Cnode
Dpos
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'index' or 'pos' which are valid but less common here.
3fill in blank
hard

Fix the error in the code to check if a node at index i has a right child in a heap of size n.

DSA C++
bool hasRightChild = (2 * i + [1]) < n;
Drag options to blanks, or click blank then click option'
A2
B3
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 2 causes wrong child index calculation.
4fill in blank
hard

Fill both blanks to calculate the parent index of a node at index i in a heap array.

DSA C++
int parent = ([1] - [2]) / 2;
Drag options to blanks, or click blank then click option'
Ai
B1
C2
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 2 instead of 1 in subtraction, or wrong variable for index.
5fill in blank
hard

Fill all three blanks to create a min heap using C++ STL priority_queue with a custom comparator.

DSA C++
std::priority_queue<int, std::vector<int>, [1]<int>> [2]; // Min heap

// Insert element
[3].push(10);
Drag options to blanks, or click blank then click option'
Agreater
BminHeap
Cpq
Dless
Attempts:
3 left
💡 Hint
Common Mistakes
Using std::less which creates max heap.
Using different variable names causing errors.