SummaryDifferent Shapes and Characteristics of Trees

Like real trees, tree data structures exhibit branching. This carries a
number of implications.

First, one must consider the degree of a tree. This refers to the
maximum number of children that a node can have. The most common form
of tree in computer science is a
binary tree, in which each node can
have up to 2 children. There are however, ternary trees, with up to 3
children, quaternary trees with up to four children, and so forth.

The next element to consider is the overall size of the tree. There are a
number of ways to quantify tree size. One is the longest path from the root
node to a leaf node. This is called the depth. If you imagine a tree as
having layers, the depth is the number of layers.

When describing a tree, it is often convenient to be able to describe its
form in detail. There are several terms which describe the form of trees.
A balanced tree is one where all of the leaves of the tree are within one
layer of one of each other. For example:

is a balanced tree, whereas the following is not:

A complete tree is a type of balanced tree, except that it has one more
additional constraint. In a balanced tree, all leaves are of depth n or
n + 1. In a complete tree, all of the leaves of depth n + 1 are further
to the left than the leaves of depth n. Furthermore, in a complete tree,
all branch nodes (except those at depth n) must have the maximum number
of children.

A perfect tree is even more particular. It requires that all of the leaves
be of the same depth and that every branching node has the maximum number
of children.