10/22/10
19:10:12
1
24
CS 61B: Lecture 24
Friday, October 22, 2010
Today’s reading:
Goodrich & Tamassia, Chapter 7.
ROOTED TREES
============
A _tree_ consists of a set of nodes and a set of edges that connect pairs of
nodes.
A tree has the property that there is exactly one path (no more, no
less) between any two nodes of the tree.
A _path_ is a connected sequence of
zero or more edges.
In a _rooted_ tree, one distinguished node is called the _root_.
Every node c,
except the root, has exactly one _parent_ node p, which is the first node
traversed on the path from c to the root.
c is p’s _child_.
The root has no
parent.
A node can have any number of children.
Some other definitions:
 A _leaf_ is a node with no children.
 _Siblings_ are nodes with the same parent.
 The _ancestors_ of a node d are the nodes on the path from d to the root.
These include d’s parent, d’s parent’s parent, d’s parent’s parent’s
parent, and so forth up to the root.
Technically, the ancestors of d also
include d itself, which makes you wonder about d’s sex life.
The root is
an ancestor of every node in the tree.
 If a is an ancestor of d, then d is a _descendant_ of a.
 The _length_ of a path is the number of edges in the path.
 The _depth_ of a node n is the length of the path from n to the root.
(The
depth of the root is zero.)
 The _height_ of a node n is the length of the path from n to its deepest
descendant.
(The height of a leaf node is zero.)
 The height of a tree is the depth of its deepest node = height of the root.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '01
 Canny
 Data Structures, Tree traversal, Tree Traversals

Click to edit the document details