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's value is less than the parent's value, and the right child's value is greater than the parent's value.
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 no nodes left.
Click to reveal answer
intermediate
What is the time complexity of searching in a balanced BST?
The time complexity is O(log n) because each step eliminates half of the remaining nodes to search.
Click to reveal answer
beginner
What happens if the value is not found in the BST during search?
The search reaches a null child (no node), meaning the value is not in the tree. The operation returns null or indicates not found.
Click to reveal answer
intermediate
Show the JavaScript code snippet for searching a value in a BST node.
function searchBST(node, val) {
if (node === null) return null;
if (node.val === val) return node;
if (val < node.val) return searchBST(node.left, val);
else return searchBST(node.right, val);
}Click to reveal answer
In a BST, where do you search if the target value is less than the current node's value?
✗ Incorrect
If the target value is less than the current node's value, the search continues in the left subtree.
What is the time complexity of searching in a balanced BST?
✗ Incorrect
In a balanced BST, the search time is O(log n) because the tree halves the search space each step.
What does the search function return if the value is not found in the BST?
✗ Incorrect
If the value is not found, the search reaches a null child and returns null.
Which property must a BST satisfy for the search operation to work correctly?
✗ Incorrect
BST property: left child values < parent, right child values > parent.
What is the first step in the BST search operation?
✗ Incorrect
The search starts by comparing the target value with the root node's value.
Explain how the search operation works in a Binary Search Tree.
Think about how you decide which side of the tree to explore.
You got /5 concepts.
Write a simple recursive function in JavaScript to search for a value in a BST.
Use if-else conditions and recursion.
You got /5 concepts.