Introduction
Imagine you have a phone book organized by last names. If the names are not evenly spread out, finding a name can take a long time. This problem happens in binary search trees when they become unbalanced, making searches slow.
Jump into concepts and practice - no test required
Imagine a library where books are arranged on shelves. If all books are stacked on one shelf, finding a book takes longer. But if books are spread evenly across shelves, you can find any book quickly by going to the right shelf.
Balanced BST:
8
/ \
4 12
/ \ / \
2 6 10 14
Unbalanced BST:
2
\
4
\
6
\
8
\
10
\
1210, 5, 1, 7, 40, 50, what is the height of the tree after balancing it?[3, 8, 10, 15, 20, 25, 30] inserted in that order. To balance it, you extract the sorted keys and rebuild the tree. Which key should be the root of the balanced BST?