0
0
DSA Goprogramming~10 mins

BST Search Operation 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 check if the current node is nil in the BST search function.

DSA Go
if root [1] nil {
    return false
}
Drag options to blanks, or click blank then click option'
A==
B!=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong logic.
Using comparison operators like '<' or '>' with nil causes errors.
2fill in blank
medium

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

DSA Go
if root.data [1] value {
    return true
}
Drag options to blanks, or click blank then click option'
A==
B!=
C<
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes incorrect search results.
Using '<' or '>' here is incorrect for equality check.
3fill in blank
hard

Fix the error in the recursive call to search the left subtree when value is less than current node's data.

DSA Go
if value [1] root.data {
    return searchBST(root.left, value)
}
Drag options to blanks, or click blank then click option'
A>
B==
C!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes searching the wrong subtree.
Using '==' or '!=' here is logically incorrect.
4fill in blank
hard

Fill both blanks to complete the recursive search for the right subtree when value is greater than current node's data.

DSA Go
if value [1] root.data {
    return searchBST(root.[2], value)
}
Drag options to blanks, or click blank then click option'
A<
Bright
C>
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong subtree search.
Using 'left' instead of 'right' causes wrong subtree search.
5fill in blank
hard

Fill all three blanks to complete the full BST search function in Go.

DSA Go
func searchBST(root *Node, value int) bool {
    if root [1] nil {
        return false
    }
    if root.data [2] value {
        return true
    }
    if value [3] root.data {
        return searchBST(root.left, value)
    } else {
        return searchBST(root.right, value)
    }
}
Drag options to blanks, or click blank then click option'
A==
B!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for nil check.
Using '!=' instead of '==' for data equality.
Using '>' instead of '<' for left subtree search.