Section 5.2: Trees and their representations

Abstract:

Trees are defined, some applications are presented, some computer representation strategies are considered, and tree traversal algorithms are discussed.

Tree Definition and Terminology

Definition: a tree is an acyclic, connected graph with one node designated as the root node.

"Because a tree is a connected graph, there is a path from the root to any other node in the tree; because the tree is acyclic, that path is unique [provided that no arc is used twice]." p. 364, Gersting.

The set of trees can also be defined recursively, as follows:

Tree terminology

Exercise #2, p. 374.

Examples of trees in action (p. 365)

Tree Representations

Binary trees (e.g. the Hexstat probability demonstrator) are special in that their children are classified as left or right. So in order to represent them, we need to specify left and right children for each node. Two representations are shown in Example 23, p. 367: a two-column array, and an adjacency list with three-field records.

Practice 20, p. 367.

Tree Traversal Algorithms

We'll look at three, which are represented recursively as follows:

displaymath136

Exercise #18, p. 377.

Each traversal method has advantages in different situations. The example we consider is binary trees as representations of arithmetic expressions.

Practice 22, p. 372.

Exercise #5, p. 374.



LONG ANDREW E
Thu Feb 28 19:18:02 EST 2002