0
0
DSA C++programming~10 mins

BST Delete Operation 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 check if the current node is null before deletion.

DSA C++
if (root == [1]) {
    return root;
}
Drag options to blanks, or click blank then click option'
Afalse
BNULL
C0
Dnullptr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or false instead of nullptr.
Using NULL which is legacy in modern C++.
2fill in blank
medium

Complete the code to find the minimum value node in the right subtree.

DSA C++
Node* minValueNode(Node* node) {
    Node* current = node;
    while (current->[1] != nullptr) {
        current = current->left;
    }
    return current;
}
Drag options to blanks, or click blank then click option'
Aleft
Bright
Cparent
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Using right pointer instead of left.
Using parent or next which are not standard BST pointers.
3fill in blank
hard

Fix the error in the recursive delete call for the right subtree.

DSA C++
root->right = deleteNode(root->right, [1]);
Drag options to blanks, or click blank then click option'
Aroot->right->val
Broot->val
Ckey
Droot->left->val
Attempts:
3 left
💡 Hint
Common Mistakes
Passing root->val instead of key.
Passing child node values instead of key.
4fill in blank
hard

Fill both blanks to replace the node's value with the inorder successor and delete it.

DSA C++
Node* temp = [1](root->right);
root->val = temp->[2];
root->right = deleteNode(root->right, temp->val);
Drag options to blanks, or click blank then click option'
AminValueNode
BmaxValueNode
Cval
Dkey
Attempts:
3 left
💡 Hint
Common Mistakes
Using maxValueNode instead of minValueNode.
Replacing with key instead of val.
5fill in blank
hard

Fill all three blanks to handle the case when the node has only one child.

DSA C++
if (root->left == nullptr) {
    Node* temp = root->[1];
    delete root;
    return [2];
} else if (root->right == nullptr) {
    Node* temp = root->[3];
    delete root;
    return temp;
}
Drag options to blanks, or click blank then click option'
Aright
Btemp
Cleft
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Returning root instead of temp.
Mixing left and right pointers.