The Binary Search Tree (BST)

Get a better understanding of the binary search tree (BST), with practical examples.

Ross Hatokay
A tree

First, before defining what a tree is, let us explore the motivation behind why and when we should it use it. For the linear data structures such as Array of size $n$ and linked list of size $n$, we have problems, namely in the time complexities when we want to perform operations:

For an array or a linked list of size $n$:

For a sorted array of size $n$:

On the other hand, as we will see, Trees (that are balanced) will neatly combine the advantages of both data structures.

What is a Tree?

A tree is a data structure that consists of nodes and edges with hierarchical relationships (parent-child). Each node consists of stored data, and of pointers to the children of that node.

A simple tree

Let’s take a look at the properties of a tree:

The idea here is that each node distributes the values to its descendants in an orderly manner. This will provide us an efficient way of navigating from the root to the leaf that contains the element, of which it’s key is closest to that we’re looking for.

What is a Binary Tree?

A binary tree is a form of a tree data structure, in which each node has at most two children, referred to as the left child and the right child.

A node in a binary tree has the following properties:

A labeled binary tree of size 9 and height 3