Binary Trees

A tree has its records (Nodes) arranged in a hierarchical way.

There is one root called a root node at the 'top' of the tree.

Connections between nodes are called branches.

A node with no branches is called a terminal node.

Example:

'Britain' is the root node.

'Avon', 'Devon' etc are terminal nodes.

This tree is not a binary tree. A binary tree is a tree where each node has at most 2 branches.

 

Constructing a binary tree.

Example : Suppose a set of records has the following key fields :

Johnson, Clay, Mullet, Ferry, Zob, Lunt

Step 1 : Place the first name as the root node.
Step 2 : Follow the left pointer if the next node is 'before' or the right pointer if it comes 'after' the root node.

'CLAY' is before 'JOHNSON'

Step 3 : 'MULLET' is after 'JOHNSON' so follow the right pointer. (Always start at the root node)
Step 4 : 'FERRY' is before 'JOHNSON' but after 'CLAY'
Step 5 : 'ZOB' is after 'JOHNSON' and after 'MULLET'
Step 6 :'LUNT' is after 'JOHNSON' but before 'MULLET'.
..and so on . If there was another node 'PARROTT' to be added can you tell where it would go?