0
0
DSA C++programming~10 mins

Bottom View of Binary Tree 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 the map that stores the bottom view nodes with their horizontal distance.

DSA C++
std::map<int, int> [1];
Drag options to blanks, or click blank then click option'
AlevelMap
BtopViewMap
CbottomViewMap
DnodeMap
Attempts:
3 left
💡 Hint
Common Mistakes
Using a map name related to top view instead of bottom view.
Using an unrelated variable name.
2fill in blank
medium

Complete the code to insert or update the bottom view map with the current node's data at its horizontal distance.

DSA C++
bottomViewMap[[1]] = node->data;
Drag options to blanks, or click blank then click option'
Aindex
Bdepth
Clevel
DhorizontalDistance
Attempts:
3 left
💡 Hint
Common Mistakes
Using level or depth instead of horizontal distance as key.
Using an undefined variable.
3fill in blank
hard

Fix the error in the queue push operation to add the left child with updated horizontal distance.

DSA C++
if (node->left) q.push(std::make_pair(node->left, [1]));
Drag options to blanks, or click blank then click option'
AhorizontalDistance - 1
BhorizontalDistance + 1
ChorizontalDistance
Dlevel - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Increasing horizontal distance for left child.
Using the same horizontal distance as parent.
4fill in blank
hard

Fill both blanks to correctly push the right child with updated horizontal distance and the current level incremented.

DSA C++
if (node->right) q.push(std::make_pair([1], [2]));
Drag options to blanks, or click blank then click option'
Anode->right
BhorizontalDistance + 1
Clevel + 1
Dnode->left
Attempts:
3 left
💡 Hint
Common Mistakes
Using left child instead of right child.
Not updating horizontal distance correctly.
5fill in blank
hard

Fill all three blanks to print the bottom view nodes in order of their horizontal distance.

DSA C++
for (auto [1] : bottomViewMap) {
    std::cout << [2] << " ";
}
std::cout << [3];
Drag options to blanks, or click blank then click option'
Aentry
Bentry.second
Cstd::endl
Dentry.first
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the key (entry.first) instead of the node data.
Forgetting to print a newline at the end.