Binary Search Tree Traversal
Now, we’ve already seen how to search, insert, and delete data from a binary search tree. I mentioned, though, that we also want to be able to print the entire list of book titles in alphabetical order. How can we do that?
First, we need the ability to visit every single node in the tree. Visiting nodes is another term for accessing them. The process of visiting every node in a data structure is known as traversing the data structure.
Second, we need to make sure we traverse the tree in alphabetically ascending order so that we can print the list in that order. You can traverse a tree in multiple ways, but for this application, we’ll perform what is known as inorder traversal, so that we can print each title in ...
Get A Common-Sense Guide to Data Structures and Algorithms in JavaScript, Volume 1 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.