This preview shows pages 1–3. Sign up to view the full content.
I
NTRODUCTION
TO
T
REES
Contents
z
Introduction: Trees and Binary Trees
{
Representing Trees
±
Test
Yourself #1
{
Tree Traversals
±
Test Yourself #2
±
Test Yourself #3
z
Answers to Self

Study Questions
Introduction
Lists, stacks, and queues, are all
linear
structures: in all three data structures, one item follows another.
Trees will be our first nonlinear structure:
z
More than one item can follow another.
z
The number of items that follow can vary from one item to another.
Trees have many uses:
z
representing family genealogies
z
as the underlying structure in decisionmaking algorithms
z
to represent priority queues (a special kind of tree called a
heap
)
z
to provide fast access to information in a database (a special kind of tree called a
btree
)
Here is the conceptual picture of a tree (of letters):
z
each letter represents one
node
z
the arrows from one node to another are called
edges
z
the topmost node (with no incoming edges) is the
root
(node A)
z
the bottom nodes (with no outgoing edges) are the
leaves
(nodes D, I, G & J)
So a (computer science) tree is kind of like an upsidedown real tree.
..
Page 1 of 6
Introduction to Trees
2008/3/27
http://pages.cs.wisc.edu/~cs3671/topics/Trees/
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentA
path
in a tree is a sequence of (zero or more) connected nodes; for example, here are 3 of the paths in
the tree shown above:
The
length
of a path is the number of nodes in the path, e.g.:
The
height
of a tree is the length of the longest path from the root to a leaf; for the above example, the
height is 4 (because the longest path from the root to a leaf is A
→
C
→
E
→
G, or A
→
C
→
E
→
J). An
empty tree has height = 0.
The
depth
of a node is the length of the path from the root to that node; for the above example:
z
the depth of J is 4
z
the depth of D is 3
z
the depth of A is 1
Given two connected nodes like this:
Node A is called the
parent
, and node B is called the
child
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '08
 MarvinSolomon
 Data Structures

Click to edit the document details