Cost of search in a chain
Warm-up · Multiple choice · about 2 min
A BST was built by inserting the keys 1, 2, …, n in increasing order. What is the worst-case cost of searching it for a key?
Example 1
Input:
[[1,2,3,4,5]]
Output:
O(n)
With n = 5, finding 5 passes all 5 nodes.
Constraints
- No rebalancing happens
Learn the idea first: Why balance matters, a visual lesson.
More Why balance matters problems
- Height after sorted inserts Warm-up
- Choose an insertion order for balance Standard
- Height of a tree Standard
- Is the tree height-balanced? Standard
- Build a balanced BST from a sorted array Challenge