October 2025
Intermediate to advanced
485 pages
13h 2m
English
In Volume 1, Chapter 15, I noted that the primary benefit of BSTs is that they maintain data in order while also providing fast searching, insertion, and deletion. While hash tables are faster than BSTs when it comes to searching, insertion, and deletion, hash tables do not maintain any order. So, if you want ordered data that is also decently fast when it comes to the other operations, BSTs are a fantastic solution.
However, as I mentioned, BSTs have a worst-case scenario to contend with. When we insert values into a BST in order, the BST becomes imbalanced. Here’s a quick refresher.
If we build a tree by inserting data in the order of 3, 2, 4, 1, 5, we get this BST:
Beautiful. It’s as balanced as ...
Read now
Unlock full access