0
0
DSA C++programming~10 mins

BST Find Minimum Element 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 return the minimum value in a BST by going left.

DSA C++
int findMin(Node* root) {
    while (root->[1] != nullptr) {
        root = root->left;
    }
    return root->data;
}
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' to find the minimum.
Trying to access a non-existent 'parent' pointer.
2fill in blank
medium

Complete the code to handle the case when the BST is empty.

DSA C++
int findMin(Node* root) {
    if (root == [1]) {
        return -1; // or some error code
    }
    while (root->left != nullptr) {
        root = root->left;
    }
    return root->data;
}
Drag options to blanks, or click blank then click option'
Anullptr
B0
CNULL
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or NULL instead of nullptr in modern C++.
Not checking for empty tree before accessing nodes.
3fill in blank
hard

Fix the error in the recursive version of findMin function.

DSA C++
int findMin(Node* root) {
    if (root == nullptr) {
        return -1;
    }
    if (root->[1] == nullptr) {
        return root->data;
    }
    return findMin(root->left);
}
Drag options to blanks, or click blank then click option'
Aright
Bparent
Cchild
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Checking right child instead of left child.
Using an incorrect pointer name.
4fill in blank
hard

Fill both blanks to complete the iterative findMin function with a for loop.

DSA C++
int findMin(Node* root) {
    for (; root != [1]; root = root->[2]) {
        if (root->left == nullptr) {
            break;
        }
    }
    return root->data;
}
Drag options to blanks, or click blank then click option'
Anullptr
BNULL
Cleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using NULL instead of nullptr.
Moving to the right child instead of left.
5fill in blank
hard

Fill all three blanks to create a recursive function that returns the minimum value in a BST.

DSA C++
int findMin(Node* root) {
    if (root == [1]) {
        return -1;
    }
    if (root->[2] == [3]) {
        return root->data;
    }
    return findMin(root->left);
}
Drag options to blanks, or click blank then click option'
Anullptr
Bleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Checking right child instead of left child.
Not checking for empty tree first.