308-203A Introduction to Computing II Lecture 13: Trees - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

308-203A Introduction to Computing II Lecture 13: Trees

Description:

Definition: A Forest is an undirected, acyclic graph. Definition ... Isomorphic tree. with parent/child relationships. K-ary trees ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 19
Provided by: alfre6
Category:

less

Transcript and Presenter's Notes

Title: 308-203A Introduction to Computing II Lecture 13: Trees


1
308-203AIntroduction to Computing IILecture
13 Trees
Fall Session 2000
2
Trees as graphs
  • Weve already seen particular examples of
  • trees, aka
  • Binary search trees
  • Call trees of recursive functions (e.g.
    Merge-sort)
  • Heaps
  • More generally trees are a special kind of
    graphs

3
Definition
Definition A Forest is an undirected, acyclic
graph
4
Definition
Definition A Free Tree is a connected,
undirected, acyclic graph
Note the connected components of a forest are
(free) trees
5
Is this really what weveseen before as trees?
We have not (yet) made any distinction of
parent or child vertices. Topologically, the
structure has the same important properties, as
we will see presently...
6
Defining Characteristics
The following statements are equivalent
1. G (V, E) is a (free) tree 2. Any two
vertices v0 and v1 in V are connected by a
unique, simple path 3. G is singly-connected
(removing any edge disconnects the graph)
More on next slide
7
Defining Characteristics
The following statements are equivalent
4. G is connected and E V -1 5. G is
acyclic and E V -1 6. G is acyclic but the
addition of any edge will create a cycle
More on previous slide
8
Proof
We prove the following sequence of the
above facts 1 ? 2 ? 3 ? 4 ? 5 ? 6 ? 1
This means any one of these six assertions
proves all the others.
9
Any questions?
10
Rooted Trees
For a tree G (V, E), pick any vertex v in V and
call it the root. All vs neighbors are
considered children of v. In this way, we can
define a parent-child relationship for
neighboring nodes in G.
11
Rooted Trees
You can think of rooting a tree in terms of the
following recursive pseudocode
RootTree(Vertex v) for u ? neighbors(v)
parent(v) u if v ? parent(u), child(u)
child(u) ? v RootTree(u)
12
Example
Consider b the root of this (otherwise free)
tree
root
c
b
h
a
d
g
b
e
f
13
Example
Consider b the root of this (otherwise free)
tree
c
b
h
a
a
d
d
g
b
e
f
14
Example
Consider b the root of this (otherwise free)
tree
c
b
h
a
a
d
d
g
b
c
g
e
f
15
Example
Consider b the root of this (otherwise free)
tree
c
b
h
a
a
d
d
g
b
c
g
e
f
h
e
f
Isomorphic tree with parent/child relationships
Original tree
16
K-ary trees
Definition A rooted tree for which every vertex
has at most k children is called a k-ary
tree. Definition In particular, a k-ary tree in
which every vertex has at most 2 children is
called binary tree. Definition A k-ary tree in
which every vertex has exactly k children is
called a complete k-ary tree.
17
Facts
  • For a complete k-ary tree with of depth d
  • There are k i nodes at depth i
  • There are n (k d - 1)/(k-1) nodes
  • Conversely, for a complete k-ary tree of n
  • nodes, the depth is
  • d logk n (k-1) 1 O( log n)

18
Any questions?
Write a Comment
User Comments (0)
About PowerShow.com