0
0
DSA C++programming~10 mins

Tree Traversal Inorder Left Root Right 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 print the left subtree first in inorder traversal.

DSA C++
void inorderTraversal(Node* root) {
    if (root == nullptr) return;
    inorderTraversal(root->[1]);
    std::cout << root->data << " ";
    inorderTraversal(root->right);
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cparent
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' causes the traversal to visit the right subtree first.
Using 'parent' or 'child' is incorrect because those are not valid pointers in this context.
2fill in blank
medium

Complete the code to print the root node's data in inorder traversal.

DSA C++
void inorderTraversal(Node* root) {
    if (root == nullptr) return;
    inorderTraversal(root->left);
    std::cout << root->[1] << " ";
    inorderTraversal(root->right);
}
Drag options to blanks, or click blank then click option'
Aleft
Bdata
Cright
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' or 'right' instead of 'data' prints pointers, not values.
Using 'value' is incorrect if the struct uses 'data' as the member name.
3fill in blank
hard

Fix the error in the inorder traversal function to correctly visit the right subtree.

DSA C++
void inorderTraversal(Node* root) {
    if (root == nullptr) return;
    inorderTraversal(root->left);
    std::cout << root->data << " ";
    inorderTraversal(root->[1]);
}
Drag options to blanks, or click blank then click option'
Aleft
Bchild
Cparent
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' again causes infinite recursion or incorrect traversal.
Using 'parent' or 'child' is invalid in this context.
4fill in blank
hard

Fill both blanks to complete the inorder traversal function that prints nodes in left-root-right order.

DSA C++
void inorderTraversal(Node* root) {
    if (root == nullptr) return;
    inorderTraversal(root->[1]);
    std::cout << root->[2] << " ";
    inorderTraversal(root->right);
}
Drag options to blanks, or click blank then click option'
Aleft
Bdata
Cright
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right pointers.
Using 'value' instead of 'data' if the struct uses 'data'.
5fill in blank
hard

Fill all three blanks to complete the inorder traversal function visiting left, root, then right.

DSA C++
void inorderTraversal(Node* root) {
    if (root == nullptr) return;
    inorderTraversal(root->[1]);
    std::cout << root->[2] << " ";
    inorderTraversal(root->[3]);
}
Drag options to blanks, or click blank then click option'
Aleft
Bdata
Cright
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'value' instead of 'data' for the node's value.
Mixing up left and right pointers.