Python Data Structures and Algorithms by Benjamin Baka

Python Data Structures and Algorithms by Benjamin Baka

Author:Benjamin Baka
Language: eng
Format: mobi, epub, pdf
Publisher: Packt Publishing
Published: 2017-12-13T11:54:17+00:00


Binary search tree implementation

Let us begin our implementation of a BST. We will want the tree to hold a reference to its own root node:

class Tree:

def __init__(self):

self.root_node = None

That's all that is needed to maintain the state of a tree. Let's examine the main operations on the tree in the next section.

Binary search tree operations

There are essentially two operations that are needful for having a usable BST. These are the insert and remove operations. These operations must occur with the one rule that they must maintain the principle that gives the BST its structure.

Before we tackle the insertion and removal of nodes, let's discuss some equally important operations that will help us better understand the insert and remove operations.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.