0
0
DSA C++programming~10 mins

Binary Tree Node Structure 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 data member for storing the node's value.

DSA C++
struct Node {
    int [1];
    Node* left;
    Node* right;
};
Drag options to blanks, or click blank then click option'
Avalue
Bnode
CdataValue
DvalNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' which is confusing as it suggests the whole node, not just the value.
Using overly long or unclear names like 'dataValue' or 'valNode'.
2fill in blank
medium

Complete the code to initialize the left child pointer to nullptr in the constructor.

DSA C++
struct Node {
    int value;
    Node* left;
    Node* right;

    Node(int val) : value(val), [1](nullptr), right(nullptr) {}
};
Drag options to blanks, or click blank then click option'
Aright
Bvalue
Cleft
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing the wrong pointer like 'right' instead of 'left'.
Trying to initialize 'value' again which is already initialized.
3fill in blank
hard

Fix the error in the constructor initializer list to correctly initialize the right child pointer.

DSA C++
struct Node {
    int value;
    Node* left;
    Node* right;

    Node(int val) : value(val), left(nullptr), [1](nullptr) {}
};
Drag options to blanks, or click blank then click option'
Aleft
Bnode
Cvalue
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing 'left' twice instead of 'right'.
Trying to initialize 'value' again which is already done.
4fill in blank
hard

Fill both blanks to complete the function that checks if a node is a leaf (no children).

DSA C++
bool isLeaf(Node* node) {
    return node->[1] == nullptr && node->[2] == nullptr;
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cvalue
Dnode
Attempts:
3 left
💡 Hint
Common Mistakes
Checking 'value' or 'node' instead of child pointers.
Checking only one child pointer instead of both.
5fill in blank
hard

Fill all three blanks to complete the function that creates a new node with given value and returns its pointer.

DSA C++
Node* createNode(int val) {
    Node* newNode = new Node([1]);
    newNode->[2] = nullptr;
    newNode->[3] = nullptr;
    return newNode;
}
Drag options to blanks, or click blank then click option'
Aval
Bleft
Cright
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'value' instead of 'val' to constructor.
Setting wrong members like 'value' instead of child pointers.
Forgetting to initialize one of the child pointers.