Why do binary search trees try to stay balanced?
To keep the height about log n, so searches stay O(log n) instead of O(n).
- To use less memory per node
- So every key appears twice
- To keep the tree's height about log n ✔
Why: Finding a key in a binary search tree walks from the root down one path, so the time depends on the tree's height. A lopsided tree can be as tall as a list, but a balanced one stays about log n tall.
Huh, didn't know that: Insert sorted numbers into a plain binary search tree and it turns into a straight line, the worst case.
Why did the binary tree go to yoga? To work on its balance.
References
Answer: To keep the tree's height about log n. Finding a key in a binary search tree walks from the root down one path, so the time depends on the tree's height. A lopsided tree can be as tall as a list, but a balanced one stays about log n tall.
- MIT 6.006 Introduction to Algorithms, Lecture 6: Binary Trees I ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/resources/mit6_006s20_lec6
Keep a binary tree balanced after insertion or deletion. Reduce O(h) running times to O(log n) by keeping h = O(log n)
Checked 2026-10-10.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.