COP 3503 – Computer Science II
–
CLASS NOTES

DAY #15
Trees differ from linked list in one important way, they are not linear structures.
Linked lists are inherently linear in their structure regardless of the number of lists
in which a particular node participates (multiply linked lists).
Traversal in a linear
list always proceeds from a particular node to either its logical predecessor or
successor node.
Only the implementation of the list will affect which node is the
logical successor or predecessor node.
A linked list cannot easily represent data
which is hierarchical in nature.
Hierarchical data exhibits ancestordescendant,
superiorsubordinate, wholepart, or similar relationships among the data elements.
The Java class hierarchy is an example of such a relationship.
As with the linked list, it is possible to represent a tree using a static data structure
although this is not common.
There is however, one instance where a static
implementation is commonly used for the purposes of speed of retrieval and we
will examine this special case later (actually it concerns a special case of a binary
tree).
The most common implementation of a tree is done dynamically and this is
the implementation we will focus upon.
Before we examine the actual
implementation issues surrounding trees, we need to focus on
what
exactly is a
tree.
There are actually two different approaches to defining a tree structure, one is a
recursive definition and the other is a nonrecursive definition.
The nonrecursive
definition basically considers a tree as a special case of a more general data
structure, the
graph
.
In this definition the tree is viewed to consist of a set of nodes
which are connected in pairs by directed edges such that the resulting graph is
connected (every node is connected to a least one other node – no node exists in
isolation) and cyclefree.
This general definition does not specify that the tree
have a root and thus a
rootedtree
is a further special case of the general tree such
every one of the node except the one designated as the root is connected to at least
one other node.
In certain situations the nonrecursive definition of a tree has
certain advantages, however, for our purposes we will focus on the recursive
definition of a tree which is:
Day 15 
1
Tree Implementations
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentA complete set of terminology has evolved for dealing with trees and we’ll look at
some of this terminology so that we too can discuss tree structures with some
degree of sophistication.
As you will see the terminology of trees is derived from
mathematical, genealogical, and botanical disciplines.
Rooted Tree:
(from the nonrecursive definition) A tree in which one node is
specified to be the
root
, (call it node
c
).
Every node (other than
c
),
call it
b
is connected by exactly one edge to exactly one other node,
call it
p
.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '09
 Computer Science, Tree traversal

Click to edit the document details