next next up down toc toc mail

7.9.  Trees

Definition 7.13 (Tree)

Let G = (V, E) be a graph with the properties
One node is distinguished called root.

Every node c [isin] V \ { root } is connected to one other node p called the parent of c.

A tree is connected in the sense, that if we start at any node n other than the root, move to the parent of n, more to the parent of the parent of n, and so on, we reach the root.

G is a tree T.

Definition 7.14 (Child)

If p is the parent of node c, we also say c is a child of p.

A node may have zero or more children, but every node other the root has exactly one parent.

Definition 7.15 (Ancestor, Descendant)

Let < [equation] > be a path in a tree T with [equation] = root. The nodes [equation] 1 [lt] i < k, are called an ancestor of [equation] and the node [equation] , 1 [lt] i < k, a descendant of node [equation]

Definition 7.16 (Siblings)

Nodes that have the same parent are called siblings.

Definition 7.17 (Leaf)

A leaf is a node of a tree T that has no children.

Definition 7.18 (Height and Depth)

In a tree T the height of a node n is the length of a longest path from n to a leaf. The height of a tree is the height of the root. The depth, or level, of a node n is the length of the path from the root to n.

Definition 7.19 (Labeled Trees)

A labeled tree is a tree in which a label or value is associated with each node of the tree.

Definition 7.20 (Subtree)

In a tree T, a node n together with all of its descendants, if any, is called a subtree of T.

We define binary trees recursivly as follows:

Definition 7.21 (Binary Tree)

The empty tree is a binary tree.

If r is a node and [equation] and [equation] are binary trees, then is the tree with root r, left subtree [equation] and right subtree [equation] is a binary tree.

Definition 7.22 (Binary Search Tree)

A binary search tree (BST) is a labeled tree in which the following property holds at every node x in the tree: All nodes of the left subtree of x have labels less than the label of x, and all nodes of the right subtree of x have labels greater than the label of x. The property is called the binary search tree property.


back next up down toc toc mail

Created by unroff & hp-tools. © by Hans-Peter Bischof. All Rights Reserved (1998).

Last modified: 27/July/98 (12:14)