0
0
DSA Goprogramming~5 mins

BST Search Operation in DSA Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a Binary Search Tree (BST)?
A Binary Search Tree is a tree data structure where each node has at most two children. The left child contains values less than the node, and the right child contains values greater than the node.
Click to reveal answer
beginner
How does the search operation work in a BST?
Start at the root. If the value equals the node's value, return it. If the value is less, search the left subtree. If greater, search the right subtree. Repeat until found or reach a null node.
Click to reveal answer
intermediate
What is the time complexity of searching in a BST?
The average time complexity is O(log n) when the tree is balanced. In the worst case (skewed tree), it can be O(n).
Click to reveal answer
intermediate
Show the Go code snippet for searching a value in a BST.
func searchBST(root *TreeNode, val int) *TreeNode { if root == nil || root.Val == val { return root } if val < root.Val { return searchBST(root.Left, val) } return searchBST(root.Right, val) }
Click to reveal answer
beginner
What happens if the searched value is not in the BST?
The search will continue down the tree until it reaches a null node, then it returns nil indicating the value is not found.
Click to reveal answer
In a BST, where do you search if the target value is less than the current node's value?
ARoot node only
BRight subtree
CBoth subtrees
DLeft subtree
What is the best case time complexity for searching in a balanced BST?
AO(log n)
BO(n)
CO(1)
DO(n log n)
What does the search function return if the value is not found in the BST?
ANil (null)
BThe last visited node
CThe root node
DAn error
Which of these is true about BST search?
ASearch visits nodes randomly
BSearch always visits every node
CSearch only visits nodes along one path from root
DSearch visits nodes in level order
If the BST is skewed (like a linked list), what is the search time complexity?
AO(log n)
BO(n)
CO(1)
DO(n log n)
Explain how the search operation works in a Binary Search Tree step-by-step.
Think about how you decide which way to go at each node.
You got /6 concepts.
    Describe the impact of tree shape on the efficiency of BST search.
    Consider how many nodes you visit in best vs worst cases.
    You got /4 concepts.