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 leaf node.

Example:

'Britain' is the root node.

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

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

The parent node is the node immediately above a node. A node only has one parent node, but a node may have 0,1 or 2 child nodes.

 

Constructing a binary tree.

Example : Suppose a set of records has the following key fields and ordering is done alphabetically :

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?