SlideShare a Scribd company logo
M O D U L E 9
P L A N A R G R A P H S
G R A P H C O L O R I N G
T R E E S A N D T R E E A P P L I C A T I O N S
T R E E T R A V E R S A L
M I N I M U M S P A N N I N G T R E E S
M O D U L E 9
P L A N A R G R A P H S
D E F I N I T I O N A N D E X A M P L E S
A graph is called planar if it can be drawn in the plane without edges crossing. Such a drawing is called a planar representation of the
graph.
Graph of
Planar
representation
of
Graph of
Planar
representation
of
E U L E R ’ S F O R M U L A
Let be a connected planar simple graph with edges and vertices. Let be number of regions in a planar representation of , then .
Graph of
has edges and
vertices. According to
Euler’s formula:
.
Planar
representation
of
𝑅1
𝑅2
𝑅3
𝑅4
Graph of
has edges and
vertices. According to
Euler’s formula:
Planar
representation
of
𝑅1
𝑅2
𝑅3
𝑅4
𝑅5
𝑅6
C O R O L L A R I E S T O E U L E R ’ S F O R M U L A
Corollary 1: If is a connected planar simple graph with edges and vertices, where , then .
Corollary 2: If is a connected planar simple graph, then has a vertex of degree not exceeding .
Corollary 3: If a connected planar simple graph has edges and vertices with and no circuits of length three, then .
Graph of Graph of
has vertices and edges.
However, from Corollary 1 is
not satisfied since . Therefore,
is nonplanar.
has no circuits of length three so
Corollary 3 can be used. has
vertices and edges. However, .
Therefore, is nonplanar.
In general, is nonplanar for .
M O D U L E 9
G R A P H C O L O R I N G
D E F I N I T I O N S
A coloring of a simple graph is the assignment of a color to each vertex of the graph so that no two adjacent vertices are assigned the same
color.
Map 1 of
regions
Dual graph of Map 1
A dual graph is a graph formed from a map
where each region is represented by a
vertex. Edges connect two vertices if the
regions represented by those vertices have
a common border. Two regions that touch
at only one point are not considered
adjacent.
Note: Any map in the plane has a planar dual
graph.
Map 2 of regions Dual graph of Map 2
A graph can be colored by assigning a different color to each
of its vertices. However, most colorings can be found in a way
that uses fewer colors than the number of vertices.
The chromatic number of a graph is the least number of colors needed for
a coloring of the graph. The chromatic number of a graph is denoted by .
F O U R C O L O R T H E O R E M
The chromatic number of a planar graph is no great than
four.
What is the chromatic
number of this graph?
Notice the chromatic number must be
at least three because and must be
different colors.
Since is blue and is green, must be red.
Since is blue and is red, must be green.
By a similar argument, must be blue and must be red.
What happens to the chromatic number
if we add an edge between and ?
Everything remains the same except that
can no longer be red. Since it also can’t be
green or blue, we need a fourth color.
E X A M P L E S
𝐾 4
𝐾 5
𝐾 3,3
𝐾 3,5
𝐶5
𝐶6
What are the chromatic numbers of these special types of
graphs?
𝜒 (𝐾 4 )=4
𝜒 (𝐾 5 )=5
for is nonplanar so the Four Color
Theorem does not apply.
In general, .
𝜒 (𝐾3,3)=2
𝜒 (𝐾3,5)=2
Recall, is bipartite so by definition,
.
𝜒 (𝐶5 )=3
𝜒 (𝐶6 )=2
In general, if is an even positive
integer with and if is an odd
positive integer with .
M O D U L E 9
T R E E S A N D T R E E A P P L I C A T I O N S
T R E E S
A tree is a connected undirected graph with no simple
circuits
Note: This implies a tree cannot contain multiple
edges or loops. So any tree must be a simple
graph
Which of these graphs are
trees?
and are trees because both are connected with no simple circuits
is not a tree because is a simple circuit
is not a tree because it is not connected
Your turn: Which of these graphs are
trees?
Answer: and
Recall: A simple circuit does not contain the same edge more than
once
R O O T E D T R E E S
A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the
root.
Any tree can be changed to a rooted tree by choosing one vertex as the
root.
Suppose is a rooted tree. If is a vertex in other than the root,
the parent of is the unique vertex such that there is a directed
edge from to and is called a child of .
is the parent of and is a child of
Vertices with the same parent are called
siblings.
and are siblings
The ancestors of a vertex other than the root
are the vertices in the path from the root to
this vertex, excluding the vertex itself and
including the root.
The ancestors of are and in the 1st
rooted tree and , , and in the 2nd
rooted tree.
The descendants of a vertex are those
vertices that have as an ancestor.
The descendants of in the 1st
rooted tree
are and . The descendants of in the 2nd
rooted tree are and .
M O R E T E R M I N O L O G Y
A vertex of a rooted tree is called a leaf if it has no
children.
The leaves are and
Vertices that have children are called internal
vertices.
The internal vertices are and
If is a vertex in a tree, the subtree with as its root is the
subgraph of the tree consisting of and its descendants
and all edges incident to these descendants.
The subtree of rooted at
B I N A R Y T R E E S
A rooted tree is called an ary tree if every internal vertex has no more than children. The tree is called a full ary tree if every internal vertex
has exactly children. Any ary tree with is called a binary tree.
is a full binary
tree since each
internal vertex
has two children
is a full ary tree since
each internal vertex has
three children
is a full ary tree since
each internal vertex
has five children
is not a full ary tree because
some of its internal vertices
have two children and
others have three. would
simply be a ary tree
O R D E R E D R O O T E D T R E E S
An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. Ordered rooted trees are drawn
so that the children of each internal vertex are shown in order from left to right.
Note: A representation of a rooted tree in the conventional way naturally determines an ordering for its edges. Such orderings
of edges will be used without explicitly mentioning an ordered tree is being considered.
In a(n) (ordered) binary tree, if an internal vertex has two children, the 1st
child is called the left child and the 2nd
child is called the right
child.
The left child of is and
the right child of is
The tree rooted at the left child of a vertex is called the left subtree of this vertex and the tree rooted at the right child of a vertex is
called the right subtree of the vertex.
The left subtree of
The right subtree of
P R O P E R T I E S O F T R E E S
A tree with vertices has edges.
Recall: An internal vertex is a vertex that has children, and a leaf is a vertex with no
children.
A full ary tree with vertices has internal vertices and leaves.
A full ary tree with internal vertices has vertices and leaves.
A full ary tree with leaves has vertices and internal vertices.
How many edges does a full binary tree with internal vertices have?
With and , there are vertices. Thus, there are edges.
B I N A R Y S E A R C H T R E E S
A binary search tree is a binary tree in which each child of a vertex is designated as a right or left child. No vertex has
more than one right child or left child and each vertex is labeled with a key, which is one of the items from a list.
Vertices are assigned keys so that the key of a vertex is both larger than the keys of all vertices in its left subtree and
smaller than the keys of all vertices in its right subtree.
Suppose we wish to implement a searching algorithm that finds items efficiently when the items are totally ordered.
This can be done through the use of a binary search tree.
Step 1: Start with a tree containing one vertex – the root. The first item in the list is assigned as the key of the
root.
Step 2: Compare the 2nd
item in the list with the key of the root. If the item is less than the key of the root, create a left child.
Otherwise, create a right child.
Step 3: Compare the next item in the list with the keys of vertices already in the tree starting at the root and moving left if the item is
less than the key of the respective vertex, or right if the item is greater than the key of the respective vertex. Add the vertex and the
key.
Step 4: Repeat Step 3 until the list of items is exhausted.
E X A M P L E
Form a binary search tree for the list using alphabetical order.
Step 1: Create the root with
the key
Step 2: Since create a right
child.
Step 3: Since create a left child Step 4: so move to the right and
compare to
Step 5: and Step 6: and Step 7: , , and Step 8: and
T H E G A M E O F N I M
Game trees can be used to model certain games. The vertices of
these trees represent the positions that a game can be in as it
progresses.
The game of nim begins with piles of stones. Two players take
turns removing one or more stones from one of the piles without
removing all of the stones left. A player without a legal move loses.
Suppose the game begins with 3 piles of stones 2, 2, and
1.
Player 1 has 3 options: (a) remove 1 stone from pile 3, (b) remove 1
stone from pile 2 (or pile 1), or (c) remove 2 stones from pile 1 or
pile 2.
Suppose player 1 goes with option (b). Then player 2 has 3 options: (a) remove 1 stone from pile 2 or pile 3, (b) remove 2
stones from pile 1, or (c) remove 1 stone from pile 1.
Suppose player 2 removes 1 stone from pile 3. Then player 1 has 3 options: (a) remove one stone from pile 2, (b) remove
1 stone from pile 1, or (c) remove 2 stones from pile 1.
If player 1 chooses options (a) or (b), player 2 will win by removing the appropriate stone. If player 1 chooses option (c), then player 1
will win.
Challenge: Create a game tree for the game of nim with 3 piles of stones. There is pile 1 has 2 stones and piles 2 and 3 have 3 stones.
M O D U L E 9
T R E E T R A V E R S A L
P R E O R D E R T R A V E R S A L
Let be an ordered rooted tree with root . If consists only of , then is the preorder traversal of . Otherwise, suppose that are
the subtrees at from left to right in . The preorder traversal begins by visiting . It continues traversing in preorder, then in
preorder, and so on, until is traversed in preorder.
In which
order does a
preorder
traversal visit
the vertices in
this ordered
rooted tree?
In the first step
we visit the root
then the subtree
with root , then ,
then the subtree
with root .
Next focusing on the
subtree with root and
the subtree with root ,
we repeat the
approach. This results
in a subtree with root
and a subtree with root
.
Focusing on the subtree with root and the subtree with
root , we are now left with only one more subtree.
This last step results in a preorder traversal
of the original tree.
I N O R D E R T R A V E R S A L
Let be an ordered rooted tree with root . If consists only of , then is the inorder traversal of . Otherwise, suppose that are the
subtrees at from left to right. The inorder traversal begins by traversing in inorder, then visiting . It continues by traversing in
inorder, then in inorder,…, and finally in inorder.
In which
order does an
inorder
traversal visit
the vertices in
this ordered
rooted tree?
Begin by visiting
the leftmost
subtree, then
visit , then visit
other subtrees
from left to right.
Next we repeat the
process starting
with the leftmost
subtree and
working left to
right.
Begin with then the root , then we’re left with one
more subtree rooted at . The subtree rooted at from
the previous step becomes .
This last step results in the inorder
transversal of the original tree.
P O S T O R D E R T R A V E R S A L
Let be an ordered rooted tree with root . If consists only of , then is the postorder traversal of . Otherwise, suppose that are
the subtrees at from left to right. The postorder traversal begins by traversing in postorder, then in postorder,…, then in
postorder, and ends by visiting .
In which
order does a
postorder
traversal visit
the vertices in
this ordered
rooted tree?
Begin by
visiting
subtrees
left to
right, then
visit the
root .
Next visit each subtree
from the previous step,
then visit the root of
each of those subtrees
as you traverse.
Continue the process visiting the subtrees from
the previous step from left to right, then visit
the root of each of those subtrees as you
traverse.
This last step results in the
postorder traversal of the original
tree.
C O M P A R I S O N
Preorder
traversal
Inorder
traversal
Postorder
transversal
M O D U L E 9
M I N I M U M S P A N N I N G T R E E S
S P A N N I N G T R E E S
Let be a simple tree. A spanning tree of is a subgraph of that is a tree containing every vertex of .
Road system in
Maine
Spanning tree of roads to
plow
The highway department wants to
plow the fewest roads so that there is
always a cleared road between any
two towns.
E X A M P L E
Find a spanning tree of the graph
shown
This graph is not a tree
because it contains
simple circuits
Remove edge to
eliminate one of the
simple circuits
Remove edge to
eliminate another
simple circuit
Remove edge to
produce a simple
graph with no simple
circuits
Other spanning trees of the original
graph
D E P T H - F I R S T S E A R C H
Arbitrarily start
at a vertex, say .
Build a path by successively
adding edges incident with
vertices not already in the
path, as long as this is
possible. This creates a path .
Use a depth-first search to find a spanning tree for the graph
shown.
Backtrack to . There is
not path beginning at
containing vertices not
already visited, so
backtrack to and form
the path .
Backtrack to and then to
. From build the path .
Backtrack to
and form the
path .
B R E A D T H - F I R S T S E A R C H
Use a breadth-first search to find a spanning tree for the graph
shown.
Arbitrarily
start at a
vertex, say .
Add edges incident with all
vertices adjacent to , so
edges from to and are
added. These edges are at
level .
Next add the edges from
these vertices to adjacent
vertices not already in the
tree. These edges are at level
.
Next add edges from
these vertices to adjacent
vertices not already in the
tree.
M I N I M U M C O S T S P A N N I N G T R E E S
A minimum (cost) spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its
edges
Weighted graph showing monthly
lease costs for lines in a computer
network
K R U S K A L’ S A L G O R I T H M
1. Order the edges in ascending order based on their
weights
2. Repeatedly select unused edges provided the edge will not create a
circuit
3. Repeat until a spanning tree is
formed
Adding creates a circuit
All vertices have been
used
total
P R I M ’ S A L G O R I T H M
1. Select an edge with minimal
weight
2. Select an edge of minimum weight incident to a vertex in the tree that does not create a simple
circuit.
3. Repeat step 2 until a spanning tree is
found
total Compare to Kruskal’s
algorithm
total
Q U E S T I O N S ?

More Related Content

PPT
Graph and Trees.pptGraph and Trees.ppt i detailed topic about graph and trees
PDF
graph theory, DS, Tree, shortest path problem
PDF
Introduction_to_Guzheng
PDF
trees-and-forest.pdf
PPTX
discrete mathematics binary%20trees.pptx
PDF
Daa chpater 12
DOCX
Apti15 4-20
Graph and Trees.pptGraph and Trees.ppt i detailed topic about graph and trees
graph theory, DS, Tree, shortest path problem
Introduction_to_Guzheng
trees-and-forest.pdf
discrete mathematics binary%20trees.pptx
Daa chpater 12
Apti15 4-20

Similar to Planer graph, graph coloring, tree and their application (20)

PPTX
TREES power point presentation BSIT 1ST YEAR
PPT
lecture 14
PPT
Lecture 5 tree.pptx
PPT
LF_Geometry_In_My_World
 
PDF
Fractions and decimals made easy
PDF
Discrete-Chapter 10 Trees
PPTX
Notes on trees Introduction and graphs.pptx
PDF
07 trees
PDF
LEC 5-DS ALGO(updated).pdf
PPTX
Chapter 10 day 1 s.a. of prisms
PPTX
Chapter 10 day 1 s.a. of prisms
PPTX
Chapter 10 day 1 s.a. of prisms
PPTX
Basic geometry
PPT
Binary search Tree and avl tree , treee.ppt
PPT
CLASS IX MATHS 6 areas of parallelogram and triangles
PPTX
Q2_PPT_Mathematics 7_Lesson 1_Week 1.pptx
DOCX
Grade-7 5As Lesson Plan on Pairs of Angles formed by Parallel Lines Cut by a ...
PPTX
MATH4-Q3-WEEK-4.pptx
PPTX
binary tree.pptx
PDF
Module 3 geometry of shape and size
TREES power point presentation BSIT 1ST YEAR
lecture 14
Lecture 5 tree.pptx
LF_Geometry_In_My_World
 
Fractions and decimals made easy
Discrete-Chapter 10 Trees
Notes on trees Introduction and graphs.pptx
07 trees
LEC 5-DS ALGO(updated).pdf
Chapter 10 day 1 s.a. of prisms
Chapter 10 day 1 s.a. of prisms
Chapter 10 day 1 s.a. of prisms
Basic geometry
Binary search Tree and avl tree , treee.ppt
CLASS IX MATHS 6 areas of parallelogram and triangles
Q2_PPT_Mathematics 7_Lesson 1_Week 1.pptx
Grade-7 5As Lesson Plan on Pairs of Angles formed by Parallel Lines Cut by a ...
MATH4-Q3-WEEK-4.pptx
binary tree.pptx
Module 3 geometry of shape and size
Ad

Recently uploaded (20)

PPTX
Sustainable Sites - Green Building Construction
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
web development for engineering and engineering
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Welding lecture in detail for understanding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPT
Mechanical Engineering MATERIALS Selection
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Sustainable Sites - Green Building Construction
Model Code of Practice - Construction Work - 21102022 .pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CYBER-CRIMES AND SECURITY A guide to understanding
Automation-in-Manufacturing-Chapter-Introduction.pdf
web development for engineering and engineering
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Foundation to blockchain - A guide to Blockchain Tech
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
bas. eng. economics group 4 presentation 1.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Welding lecture in detail for understanding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Mechanical Engineering MATERIALS Selection
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Ad

Planer graph, graph coloring, tree and their application

  • 1. M O D U L E 9 P L A N A R G R A P H S G R A P H C O L O R I N G T R E E S A N D T R E E A P P L I C A T I O N S T R E E T R A V E R S A L M I N I M U M S P A N N I N G T R E E S
  • 2. M O D U L E 9 P L A N A R G R A P H S
  • 3. D E F I N I T I O N A N D E X A M P L E S A graph is called planar if it can be drawn in the plane without edges crossing. Such a drawing is called a planar representation of the graph. Graph of Planar representation of Graph of Planar representation of
  • 4. E U L E R ’ S F O R M U L A Let be a connected planar simple graph with edges and vertices. Let be number of regions in a planar representation of , then . Graph of has edges and vertices. According to Euler’s formula: . Planar representation of 𝑅1 𝑅2 𝑅3 𝑅4 Graph of has edges and vertices. According to Euler’s formula: Planar representation of 𝑅1 𝑅2 𝑅3 𝑅4 𝑅5 𝑅6
  • 5. C O R O L L A R I E S T O E U L E R ’ S F O R M U L A Corollary 1: If is a connected planar simple graph with edges and vertices, where , then . Corollary 2: If is a connected planar simple graph, then has a vertex of degree not exceeding . Corollary 3: If a connected planar simple graph has edges and vertices with and no circuits of length three, then . Graph of Graph of has vertices and edges. However, from Corollary 1 is not satisfied since . Therefore, is nonplanar. has no circuits of length three so Corollary 3 can be used. has vertices and edges. However, . Therefore, is nonplanar. In general, is nonplanar for .
  • 6. M O D U L E 9 G R A P H C O L O R I N G
  • 7. D E F I N I T I O N S A coloring of a simple graph is the assignment of a color to each vertex of the graph so that no two adjacent vertices are assigned the same color. Map 1 of regions Dual graph of Map 1 A dual graph is a graph formed from a map where each region is represented by a vertex. Edges connect two vertices if the regions represented by those vertices have a common border. Two regions that touch at only one point are not considered adjacent. Note: Any map in the plane has a planar dual graph. Map 2 of regions Dual graph of Map 2 A graph can be colored by assigning a different color to each of its vertices. However, most colorings can be found in a way that uses fewer colors than the number of vertices. The chromatic number of a graph is the least number of colors needed for a coloring of the graph. The chromatic number of a graph is denoted by .
  • 8. F O U R C O L O R T H E O R E M The chromatic number of a planar graph is no great than four. What is the chromatic number of this graph? Notice the chromatic number must be at least three because and must be different colors. Since is blue and is green, must be red. Since is blue and is red, must be green. By a similar argument, must be blue and must be red. What happens to the chromatic number if we add an edge between and ? Everything remains the same except that can no longer be red. Since it also can’t be green or blue, we need a fourth color.
  • 9. E X A M P L E S 𝐾 4 𝐾 5 𝐾 3,3 𝐾 3,5 𝐶5 𝐶6 What are the chromatic numbers of these special types of graphs? 𝜒 (𝐾 4 )=4 𝜒 (𝐾 5 )=5 for is nonplanar so the Four Color Theorem does not apply. In general, . 𝜒 (𝐾3,3)=2 𝜒 (𝐾3,5)=2 Recall, is bipartite so by definition, . 𝜒 (𝐶5 )=3 𝜒 (𝐶6 )=2 In general, if is an even positive integer with and if is an odd positive integer with .
  • 10. M O D U L E 9 T R E E S A N D T R E E A P P L I C A T I O N S
  • 11. T R E E S A tree is a connected undirected graph with no simple circuits Note: This implies a tree cannot contain multiple edges or loops. So any tree must be a simple graph Which of these graphs are trees? and are trees because both are connected with no simple circuits is not a tree because is a simple circuit is not a tree because it is not connected Your turn: Which of these graphs are trees? Answer: and Recall: A simple circuit does not contain the same edge more than once
  • 12. R O O T E D T R E E S A rooted tree is a tree in which one vertex has been designated as the root and every edge is directed away from the root. Any tree can be changed to a rooted tree by choosing one vertex as the root. Suppose is a rooted tree. If is a vertex in other than the root, the parent of is the unique vertex such that there is a directed edge from to and is called a child of . is the parent of and is a child of Vertices with the same parent are called siblings. and are siblings The ancestors of a vertex other than the root are the vertices in the path from the root to this vertex, excluding the vertex itself and including the root. The ancestors of are and in the 1st rooted tree and , , and in the 2nd rooted tree. The descendants of a vertex are those vertices that have as an ancestor. The descendants of in the 1st rooted tree are and . The descendants of in the 2nd rooted tree are and .
  • 13. M O R E T E R M I N O L O G Y A vertex of a rooted tree is called a leaf if it has no children. The leaves are and Vertices that have children are called internal vertices. The internal vertices are and If is a vertex in a tree, the subtree with as its root is the subgraph of the tree consisting of and its descendants and all edges incident to these descendants. The subtree of rooted at
  • 14. B I N A R Y T R E E S A rooted tree is called an ary tree if every internal vertex has no more than children. The tree is called a full ary tree if every internal vertex has exactly children. Any ary tree with is called a binary tree. is a full binary tree since each internal vertex has two children is a full ary tree since each internal vertex has three children is a full ary tree since each internal vertex has five children is not a full ary tree because some of its internal vertices have two children and others have three. would simply be a ary tree
  • 15. O R D E R E D R O O T E D T R E E S An ordered rooted tree is a rooted tree where the children of each internal vertex are ordered. Ordered rooted trees are drawn so that the children of each internal vertex are shown in order from left to right. Note: A representation of a rooted tree in the conventional way naturally determines an ordering for its edges. Such orderings of edges will be used without explicitly mentioning an ordered tree is being considered. In a(n) (ordered) binary tree, if an internal vertex has two children, the 1st child is called the left child and the 2nd child is called the right child. The left child of is and the right child of is The tree rooted at the left child of a vertex is called the left subtree of this vertex and the tree rooted at the right child of a vertex is called the right subtree of the vertex. The left subtree of The right subtree of
  • 16. P R O P E R T I E S O F T R E E S A tree with vertices has edges. Recall: An internal vertex is a vertex that has children, and a leaf is a vertex with no children. A full ary tree with vertices has internal vertices and leaves. A full ary tree with internal vertices has vertices and leaves. A full ary tree with leaves has vertices and internal vertices. How many edges does a full binary tree with internal vertices have? With and , there are vertices. Thus, there are edges.
  • 17. B I N A R Y S E A R C H T R E E S A binary search tree is a binary tree in which each child of a vertex is designated as a right or left child. No vertex has more than one right child or left child and each vertex is labeled with a key, which is one of the items from a list. Vertices are assigned keys so that the key of a vertex is both larger than the keys of all vertices in its left subtree and smaller than the keys of all vertices in its right subtree. Suppose we wish to implement a searching algorithm that finds items efficiently when the items are totally ordered. This can be done through the use of a binary search tree. Step 1: Start with a tree containing one vertex – the root. The first item in the list is assigned as the key of the root. Step 2: Compare the 2nd item in the list with the key of the root. If the item is less than the key of the root, create a left child. Otherwise, create a right child. Step 3: Compare the next item in the list with the keys of vertices already in the tree starting at the root and moving left if the item is less than the key of the respective vertex, or right if the item is greater than the key of the respective vertex. Add the vertex and the key. Step 4: Repeat Step 3 until the list of items is exhausted.
  • 18. E X A M P L E Form a binary search tree for the list using alphabetical order. Step 1: Create the root with the key Step 2: Since create a right child. Step 3: Since create a left child Step 4: so move to the right and compare to Step 5: and Step 6: and Step 7: , , and Step 8: and
  • 19. T H E G A M E O F N I M Game trees can be used to model certain games. The vertices of these trees represent the positions that a game can be in as it progresses. The game of nim begins with piles of stones. Two players take turns removing one or more stones from one of the piles without removing all of the stones left. A player without a legal move loses. Suppose the game begins with 3 piles of stones 2, 2, and 1. Player 1 has 3 options: (a) remove 1 stone from pile 3, (b) remove 1 stone from pile 2 (or pile 1), or (c) remove 2 stones from pile 1 or pile 2. Suppose player 1 goes with option (b). Then player 2 has 3 options: (a) remove 1 stone from pile 2 or pile 3, (b) remove 2 stones from pile 1, or (c) remove 1 stone from pile 1. Suppose player 2 removes 1 stone from pile 3. Then player 1 has 3 options: (a) remove one stone from pile 2, (b) remove 1 stone from pile 1, or (c) remove 2 stones from pile 1. If player 1 chooses options (a) or (b), player 2 will win by removing the appropriate stone. If player 1 chooses option (c), then player 1 will win. Challenge: Create a game tree for the game of nim with 3 piles of stones. There is pile 1 has 2 stones and piles 2 and 3 have 3 stones.
  • 20. M O D U L E 9 T R E E T R A V E R S A L
  • 21. P R E O R D E R T R A V E R S A L Let be an ordered rooted tree with root . If consists only of , then is the preorder traversal of . Otherwise, suppose that are the subtrees at from left to right in . The preorder traversal begins by visiting . It continues traversing in preorder, then in preorder, and so on, until is traversed in preorder. In which order does a preorder traversal visit the vertices in this ordered rooted tree? In the first step we visit the root then the subtree with root , then , then the subtree with root . Next focusing on the subtree with root and the subtree with root , we repeat the approach. This results in a subtree with root and a subtree with root . Focusing on the subtree with root and the subtree with root , we are now left with only one more subtree. This last step results in a preorder traversal of the original tree.
  • 22. I N O R D E R T R A V E R S A L Let be an ordered rooted tree with root . If consists only of , then is the inorder traversal of . Otherwise, suppose that are the subtrees at from left to right. The inorder traversal begins by traversing in inorder, then visiting . It continues by traversing in inorder, then in inorder,…, and finally in inorder. In which order does an inorder traversal visit the vertices in this ordered rooted tree? Begin by visiting the leftmost subtree, then visit , then visit other subtrees from left to right. Next we repeat the process starting with the leftmost subtree and working left to right. Begin with then the root , then we’re left with one more subtree rooted at . The subtree rooted at from the previous step becomes . This last step results in the inorder transversal of the original tree.
  • 23. P O S T O R D E R T R A V E R S A L Let be an ordered rooted tree with root . If consists only of , then is the postorder traversal of . Otherwise, suppose that are the subtrees at from left to right. The postorder traversal begins by traversing in postorder, then in postorder,…, then in postorder, and ends by visiting . In which order does a postorder traversal visit the vertices in this ordered rooted tree? Begin by visiting subtrees left to right, then visit the root . Next visit each subtree from the previous step, then visit the root of each of those subtrees as you traverse. Continue the process visiting the subtrees from the previous step from left to right, then visit the root of each of those subtrees as you traverse. This last step results in the postorder traversal of the original tree.
  • 24. C O M P A R I S O N Preorder traversal Inorder traversal Postorder transversal
  • 25. M O D U L E 9 M I N I M U M S P A N N I N G T R E E S
  • 26. S P A N N I N G T R E E S Let be a simple tree. A spanning tree of is a subgraph of that is a tree containing every vertex of . Road system in Maine Spanning tree of roads to plow The highway department wants to plow the fewest roads so that there is always a cleared road between any two towns.
  • 27. E X A M P L E Find a spanning tree of the graph shown This graph is not a tree because it contains simple circuits Remove edge to eliminate one of the simple circuits Remove edge to eliminate another simple circuit Remove edge to produce a simple graph with no simple circuits Other spanning trees of the original graph
  • 28. D E P T H - F I R S T S E A R C H Arbitrarily start at a vertex, say . Build a path by successively adding edges incident with vertices not already in the path, as long as this is possible. This creates a path . Use a depth-first search to find a spanning tree for the graph shown. Backtrack to . There is not path beginning at containing vertices not already visited, so backtrack to and form the path . Backtrack to and then to . From build the path . Backtrack to and form the path .
  • 29. B R E A D T H - F I R S T S E A R C H Use a breadth-first search to find a spanning tree for the graph shown. Arbitrarily start at a vertex, say . Add edges incident with all vertices adjacent to , so edges from to and are added. These edges are at level . Next add the edges from these vertices to adjacent vertices not already in the tree. These edges are at level . Next add edges from these vertices to adjacent vertices not already in the tree.
  • 30. M I N I M U M C O S T S P A N N I N G T R E E S A minimum (cost) spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges Weighted graph showing monthly lease costs for lines in a computer network
  • 31. K R U S K A L’ S A L G O R I T H M 1. Order the edges in ascending order based on their weights 2. Repeatedly select unused edges provided the edge will not create a circuit 3. Repeat until a spanning tree is formed Adding creates a circuit All vertices have been used total
  • 32. P R I M ’ S A L G O R I T H M 1. Select an edge with minimal weight 2. Select an edge of minimum weight incident to a vertex in the tree that does not create a simple circuit. 3. Repeat step 2 until a spanning tree is found total Compare to Kruskal’s algorithm total
  • 33. Q U E S T I O N S ?