Reqflow
Searching·Intermediate

BST: Search

Time O(h)Space O(h)
·

A Binary Search Tree stores values so that every node's left subtree contains only smaller values and every right subtree contains only larger values. Search starts at the root and at each node makes one comparison: go left if target is smaller, right if larger, or return found if equal. In a balanced BST this takes O(log n) time.

Example: Find 6 in a BST.

When to use this

See also

← All algorithms