Binary Search Trees in Action
We’ve seen that binary search trees boast efficiencies of O(log N) for search, insertion, and deletion, making it an efficient choice for scenarios in which we need to store and manipulate ordered data. This is particularly true if we’ll be modifying the data often, because while ordered arrays are just as fast as binary search trees when searching data, binary search trees are significantly faster when it comes to inserting and deleting data.
For example, let’s say we’re creating an application that maintains a list of book titles. We’d want our application to have the following functionality:
-
Our program should be able to print the list of book titles in alphabetical order.
-
Our program should allow for constant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access