0
0
DSA C++programming~10 mins

BST Search 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 in the BST search function.

DSA C++
if (root == [1]) {
    return false;
}
Drag options to blanks, or click blank then click option'
Aroot
Bnullptr
C0
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of nullptr
Comparing to 0 instead of nullptr
2fill in blank
medium

Complete the code to compare the search key with the current node's data.

DSA C++
if (key == root->[1]) {
    return true;
}
Drag options to blanks, or click blank then click option'
Akey
Bvalue
Cdata
Dval
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect member names like 'value' or 'key'
Trying to access non-existent members
3fill in blank
hard

Fix the error in the recursive call to search in the left subtree.

DSA C++
return searchBST(root->[1], key);
Drag options to blanks, or click blank then click option'
Aleft
Bparent
Cright
Dchild
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' for left subtree
Using non-existent pointers like 'parent' or 'child'
4fill in blank
hard

Fill both blanks to complete the recursive search in the right subtree when key is greater.

DSA C++
if (key > root->[1]) {
    return searchBST(root->[2], key);
}
Drag options to blanks, or click blank then click option'
Adata
Bleft
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'left' instead of 'right' for the subtree
Using incorrect member names
5fill in blank
hard

Fill all three blanks to complete the BST search function.

DSA C++
bool searchBST(Node* root, int key) {
    if (root == [1]) return false;
    if (key == root->[2]) return true;
    if (key < root->[3]) return searchBST(root->left, key);
    else return searchBST(root->right, key);
}
Drag options to blanks, or click blank then click option'
Anullptr
Bdata
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of nullptr
Using wrong member names for node data