Binary Trees

A binary tree is a dynamic data structure that allows for efficient sorting, searching and retrieval of data.  A binary tree can reflect structural relationships in data such as hierarchies.

Advantages of binary trees

  • Trees reflect structural relationships in the data.
  • Trees are used to represent hierarchies.
  • Trees provide efficient methods for insertion and searching of data.
  • Trees are very flexible data, allowing you to move subtrees around with little effort.

Terminology

A binary tree consists of nodes connected by branches.

The node at the top of the hierarchy is known as the root node.  In the example below, Lewis is the root node.

Each node can have none, one or two children.  A node with no children is called a terminal node, or a leaf node.  In the example below, Harry, James, Rachael and Xavier are terminal nodes.