0
0
DSA C++programming~10 mins

Tree Traversal Postorder Left Right Root 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 call the postorder traversal function recursively on the left child.

DSA C++
void postorder(Node* root) {
    if (root == nullptr) return;
    postorder(root->[1]);
    // Continue traversal
}
Drag options to blanks, or click blank then click option'
Aright
Bchild
Cparent
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Calling postorder on root->right first.
Calling postorder on root->parent which does not exist.
Using an incorrect pointer name.
2fill in blank
medium

Complete the code to call the postorder traversal function recursively on the right child.

DSA C++
void postorder(Node* root) {
    if (root == nullptr) return;
    postorder(root->left);
    postorder(root->[1]);
    // Continue traversal
}
Drag options to blanks, or click blank then click option'
Aright
Bparent
Cchild
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Calling postorder on root->left again.
Using root->parent which is not part of traversal.
Using an invalid pointer name.
3fill in blank
hard

Fix the error in the code to print the root node's value after traversing left and right subtrees.

DSA C++
void postorder(Node* root) {
    if (root == nullptr) return;
    postorder(root->left);
    postorder(root->right);
    std::cout << root->[1] << " ";
}
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cdata
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Printing root->left or root->right which are pointers.
Using root->value which may not exist.
Forgetting to print the root node.
4fill in blank
hard

Fill both blanks to complete the postorder traversal function that returns a vector of node values.

DSA C++
void postorder(Node* root, std::vector<int>& result) {
    if (root == nullptr) return;
    postorder(root->[1], result);
    postorder(root->[2], result);
    result.push_back(root->data);
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cparent
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right child pointers.
Using 'parent' or 'child' which are invalid pointers.
Forgetting to pass 'result' vector.
5fill in blank
hard

Fill all three blanks to create a postorder traversal that returns a map from node data to its depth in the tree.

DSA C++
void postorder(Node* root, std::map<int, int>& depthMap, int depth) {
    if (root == nullptr) return;
    postorder(root->[1], depthMap, depth + 1);
    postorder(root->[2], depthMap, depth + 1);
    depthMap[root->[3]] = depth;
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cdata
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'data' for node value.
Swapping left and right pointers.
Not incrementing depth correctly.