Professional Documents
Culture Documents
1
Tree
2
Which graphs are trees?
a) b)
c)
3
Specify a vertex as root
4
Specify a root.
ROOT
a)
5
Specify a root.
ROOT
a)
6
Specify a root.
ROOT
a)
A directed graph called
a rooted tree results.
7
What if a different root is chosen?
ROOT
a)
8
What if a different root is chosen?
ROOT
a)
9
What if a different root is chosen?
ROOT
a)
10
What if a different root is chosen?
a)
A different
rooted tree results.
11
Jake’s Pizza Shop Tree
Application in
organizations Owner Jake
12
A Tree Has a Root
TREE ROOT
Owner Jake
13
Leaf nodes have no children
Owner Jake
LEAF NODES
14
A Tree Has Levels
15
Level One
Owner Jake
16
Level Two
Owner Jake
LEVEL 2
17
Sibling nodes have same parent
Owner Jake
SIBLINGS
Manager Brad Chef Carol
18
Sibling nodes have same parent
Owner Jake
SIBLINGS
19
A Subtree
ROOT
Owner Jake
22
How many internal vertices?
Owner Jake
23
Binary Tree
24
Ordered Binary Tree
25
Tree Properties
Theorem 2. A tree with N vertices has N-1 edges.
26
An Ordered Binary Tree
Lou
Hal Max
Ed Ken Sue
Joe Ted
27
Parent
28
What is the parent of Ed?
Lou
Hal Max
Ed Ken Sue
Joe Ted
29
Leaf
30
How many leaves?
Lou
Hal Max
Ed Ken Sue
Joe Ted
31
Ancestors
32
How many ancestors of Ken?
Lou
Hal Max
Ed Ken Sue
Joe Ted
33
Descendants
34
How many descendants of Hal?
Lou
Hal Max
Ed Ken Sue
Joe Ted
35
Level
36
What is the level of Ted?
Lou
Hal Max
Ed Ken Sue
Joe Ted
37
Height
38
What is the height?
Lou
Hal Max
Ed Ken Sue
Joe Ted
39
Balanced
40
Is this binary tree balanced?
Lou
Hal Max
Ed Ken Sue
Joe Ted
41
Searching takes time . . .
42
A Binary Search Tree (BST) is . . .
A special kind of binary tree in which:
1. Each vertex contains a distinct key value,
2. The key values in the tree can be compared using “greater
than” and “less than”, and
3. The key value of each vertex in the tree is
less than every key value in its right subtree, and greater
than every key value in its left subtree.
Is ‘F’ in the binary search tree?
‘J’
‘E’ ‘T’
‘S’
44
Decision Trees
Rooted Trees
can be used to
model problems
in which a series
of decision
leads to a
solution
eg. Chess 45
Efficient Use of Decision Trees
46
Data compression
• For Data Compression, Huffman coding is
used. Basis of this coding necessitates the
efficient use of tree algorithms.
47
Practice
• Read chapter 9 of Rosen’s book and practice
all examples!
Thanks you !
48