1. Current node
Start searching at the root.
let node = rootTyporithm · medium
Step 1 of 8 · intro card
Search Algorithms
Binary Search Tree Search follows left or right child pointers based on the BST ordering rule.
A BST stores smaller values in the left subtree and larger values in the right subtree.
At each node, compare target with node.value.
A smaller target moves left; a larger target moves right.
Search stops when the value is found or a null child is reached.
Start at the root.
Compare target with node.value.
Go left for smaller values.
Go right for larger values.
Balanced trees search in O(log n).
function bstSearch(root, target) {
let node = root;
while (node) {
if (node.value === target) return node;
if (target < node.value) {
node = node.left;
} else {
node = node.right;
}
}
return null;
}Connect each part of the code to the concept before you type.
Start searching at the root.
let node = rootKeep going while there is a node to inspect.
while (node)Return the node when its value matches target.
if (node.value === target) return nodeSmaller target values must be in the left subtree.
target < node.valueFollow the left child pointer.
node = node.leftFollow the right child pointer for larger targets.
node = node.rightA missing child means the target is not in the tree.
return nullRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.
Algorithm lab · interactive
InputBST root 8 · target 6
Follow temporary values, local state and supporting structures at this step.
No temporary values have been saved in this frame yet.
Around this step
Small, reproducible examples · ← → step · Space play/pause · Home/End first/last state