0
0
DSA Goprogramming~10 mins

BST Find Minimum Element in DSA Go - 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 the BST.

DSA Go
func findMin(root *Node) int {
    current := root
    for current.[1] != nil {
        current = current.left
    }
    return current.val
}
Drag options to blanks, or click blank then click option'
Aleft
Bchild
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' to traverse.
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 Go
func findMin(root *Node) int {
    if root == [1] {
        return -1 // or error code
    }
    current := root
    for current.left != nil {
        current = current.left
    }
    return current.val
}
Drag options to blanks, or click blank then click option'
A0
Bnil
Cfalse
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Checking root == 0 instead of root == nil.
Not handling empty tree case.
3fill in blank
hard

Fix the error in the loop condition to correctly find the minimum element.

DSA Go
func findMin(root *Node) int {
    current := root
    for current.[1] != nil {
        current = current.left
    }
    return current.val
}
Drag options to blanks, or click blank then click option'
Aparent
Bright
Cchild
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' in the loop condition.
Checking the wrong child pointer.
4fill in blank
hard

Fill both blanks to complete the recursive function to find the minimum element.

DSA Go
func findMin(root *Node) int {
    if root == [1] {
        return -1
    }
    if root.[2] == nil {
        return root.val
    }
    return findMin(root.left)
}
Drag options to blanks, or click blank then click option'
Anil
Broot
Cleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Checking root.right instead of root.left.
Not handling nil root case.
5fill in blank
hard

Fill all three blanks to create a function that returns the minimum node's value or -1 if empty.

DSA Go
func findMin(root *Node) int {
    if root == [1] {
        return -1
    }
    current := root
    for current.[2] != [3] {
        current = current.left
    }
    return current.val
}
Drag options to blanks, or click blank then click option'
Anil
Bleft
Dright
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' instead of 'left' in the loop.
Comparing to wrong nil pointer.