Skip to Content
A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 1
book

A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 1

by Jay Wengrow
December 2023
Intermediate to advanced content levelIntermediate to advanced
504 pages
11h 43m
English
Pragmatic Bookshelf
Content preview from A Common-Sense Guide to Data Structures and Algorithms in Python, Volume 1

Insertion

As I mentioned earlier, binary search trees are at their best when it comes to insertion. Now we’ll see why.

Say we want to insert the number 45 into our example tree. The first thing we’d have to do is find the correct node to attach the 45 to. To begin our search, we start at the root:

images/binary_trees/bst_6.png

Since 45 is less than 50, we drill down to the left child:

images/binary_trees/bst_10.png

Since 45 is greater than 25, we must inspect the right child:

images/binary_trees/bst_11.png

Since 45 is greater than 33, we ...

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.
Start your free trial

You might also like

Data Structures & Algorithms in Python

Data Structures & Algorithms in Python

John Canning, Alan Broder, Robert Lafore
Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

Publisher Resources

ISBN: 9798888650776Errata Page