Skip to Content
Hands-On Data Structures and Algorithms with Python - Second Edition
book

Hands-On Data Structures and Algorithms with Python - Second Edition

by Dr. Basant Agarwal, Benjamin Baka, David Julian
October 2018
Beginner to intermediate
398 pages
11h 1m
English
Packt Publishing
Content preview from Hands-On Data Structures and Algorithms with Python - Second Edition

Inserting nodes

One of the most important operations to implement on a binary search tree is to insert data items in the tree. As we have already discussed, regarding the properties of the binary search tree, for each node in the tree, the left child nodes should contain the data less than their own value and the right child nodes should have data greater than their value. So, we have to ensure that the property of the binary search tree satisfies whenever we insert an item in the tree.

For example, let's create a binary search tree by inserting data items 5, 3, 7, and 1 in the tree. Consider the following:

  1. Insert 5: We start with the first data item, 5. To do this, we will create a node with its data attribute set to 5, since it is the ...
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

Hands-On Data Structures and Algorithms with Python - Third Edition

Hands-On Data Structures and Algorithms with Python - Third Edition

Dr. Basant Agarwal
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: 9781788995573Supplemental Content