SlideShare a Scribd company logo
1 of 16
Download to read offline
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
1
Euler and Hamilton Paths:
DEFINITION 1:
An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path in G is a
simple path containing every edge of G.
Examples 1 and 2 illustrate the concept of Euler circuits and paths.
Example 1:
Which of the undirected graphs in Figure 1 have an Euler circuit? Of those that do not, which have
an Euler path?
Figure 1: The undirected graphs G1, G2 and G3
Solution:
The graph G1 has an Euler circuit, for example, a, e, c, d, e, b, a. Neither of the graphs G2 or G3 has
an Euler circuit. However, G3 has an Euler path, namely, a, c, d, e, b, d, a, b. G2 does not have an
Euler path.
Example 2:
Which of the directed graphs in Figure 2 have an Euler circuit? Of those that do not, which have an
Euler path?
Figure 2: The directed graphs H1, H2 and H3
Solution:
The graph H2 has an Euler circuit, for example, a, g, c, b, g, e, d, f, a. Neither H1 nor H3 has an Euler
circuit. H3 has an Euler path, namely, c, a, b, c, d, b, but H1 does not.
Theorem 1:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
2
A connected multigraph with at least two vertices has an Euler circuit if and only if each of its
vertices has even degree.
Theorem 2:
A connected multigraph has an Euler path but not an Euler circuit if and only if it has exactly two
vertices of odd degree.
Example 3:
Which graphs shown in Figure 3 have an Euler path?
Figure 3: Three undirected graphs
Solution:
G1 contains exactly two vertices of odd degree, namely, b and d. Hence, it has an Euler path that
must have b and d as its endpoints. One such Euler path is d, a, b, c, d, b. Similarly,G2 has exactly two
vertices of odd degree, namely, b and d. So it has an Euler path that must have b and d as endpoints.
One such Euler path is b, a, g, f, e, d, c, g, b, c, f, d. G3 has no Euler path because it has six vertices of
odd degree.
DEFINITION 2:
A Hamilton circuit in a graph G is a closed path that visits every vertex in G exactly once. Note that
an Euler circuit traverses every edge exactly once, but may repeat vertices, while a Hamilton circuit
visits each vertex exactly once but may repeat edges.
Example 4:
Which of the simple graphs in Figure 4 have a Hamilton circuit or, if not, a Hamilton path?
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
3
Figure 4: Three simple graphs
Solution:
G1 has a Hamilton circuit: a, b, c, d, e, a. There is no Hamilton circuit in G2. But G2 does have a
Hamilton path, namely, a, b, c, d. G3 has neither a Hamilton circuit nor a Hamilton path.
Example 5:
Show that neither graph displayed in Figure 5 has a Hamilton circuit.
Figure 5: Two graphs that do not have a Hamilton circuit
Solution:
There is no Hamilton circuit in G because G has a vertex of degree one, namely, e. However, G has a
Hamilton path, namely, e,d,a,b,c.
Now consider H. Because the degrees of the vertices a, b, d, and e are all two, every edge incident
with these vertices must be part of any Hamilton circuit. It is now easy to see that no Hamilton
circuit can exist in H, for any Hamilton circuit would have to contain four edges incident with c,
which is impossible. H has a Hamilton path: a,b,c,d,e.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
4
Shortest-Path Problems:
Dijkstra’s Algorithm:
Example 1:
Use Dijkstra’s algorithm to find the length of a shortest path between the vertices a and z in the
weighted graph displayed in Figure 1(a).
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
5
Figure 1: Using Dijkstra’s Algorithm to Find a Shortest Path from a to z.
Solution:
The steps used by Dijkstra’s algorithm to find a shortest path between a and z are shown in Figure 1.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
6
Introduction to Trees:
DEFINITION 1:
A tree is a connected undirected graph with no simple circuits.
Example 1:
Which of the graphs shown in Figure 1 are trees?
Figure 1: Example of trees and non-trees
Solution:
G1 and G2 are trees, because both are connected graphs with no simple circuits. G3 is not a tree
because e, b, a, d, e is a simple circuit in this graph. Finally, G4 is not a tree because it is not
connected.
Forests:
forests have the property that each of their connected components is a tree. Figure 2 displays a
forest.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
7
Figure 2: Example of a forest
DEFINITION 2:
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.
Figure 3: A tree and rooted trees formed by designating two different roots.
For instance, Figure 3 displays the rooted trees formed by designating a to be the root and c to be
the root, respectively, in the tree T.
Tree Terminology:
Suppose that T is a rooted tree. If v is a vertex in T other than the root, the parent of v is the unique
vertex u such that there is a directed edge from u to v. When u is the parent of v, v is called a child of
u. Vertices with the same parent are called 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 descendants of a vertex v are those vertices that have v as an ancestor. A vertex of a
rooted tree is called a leaf if it has no children. Vertices that have children are called internal
vertices.
If a is a vertex in a tree, the subtree with a as its root is the subgraph of the tree consisting of a and
its descendants and all edges incident to these descendants.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
8
Example 2:
In the rooted tree T (with root a) shown in Figure 4, find the parent of c, the children of g, the
siblings of h, all ancestors of e, all descendants of b, all internal vertices, and all leaves. What is the
subtree rooted at g?
Figure 4: A rooted tree T
Solution:
The parent of c is b. The children of g are h, i, and j. The siblings of h are i and j. The ancestors of e
are c, b, and a. The descendants of b are c, d, and e. The internal vertices are a, b, c, g, h, and j. The
leaves are d, e, f , i, k, l, and m. The subtree rooted at g is shown in Figure 5.
Figure 5: The subtree rooted at g
DEFINITION 3:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
9
A rooted tree is called an m-ary tree if every internal vertex has no more than m children. The tree is
called a full m-ary tree if every internal vertex has exactly m children. An m-ary tree with m = 2 is
called a binary tree.
Example 3:
Are the rooted trees in Figure 6 full m-ary trees for some positive integer m?
Solution:
Figure 6: Four rooted trees
T1 is a full binary tree because each of its internal vertices has two children. T2 is a full 3-ary tree
because each of its internal vertices has three children. In T3 each internal vertex has five children,
so T3 is a full 5-ary tree. T4 is not a full m-ary tree for any m because some of its internal vertices
have two children and others have three children.
Example 4:
What are the left and right children of d in the binary tree T shown in Figure 7(a)? What are the left
and right subtrees of c?
Solution:
Figure 7: A binary tree T and left and right subtrees of the vertex c
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
10
The left child of d is f and the right child is g. We show the left and right subtrees of c in Figures 7(b)
and 7(c), respectively.
More about trees:
The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex.
The level of the root is defined to be zero. The height of a rooted tree is the maximum of the levels
of vertices. In other words, the height of a rooted tree is the length of the longest path from the root
to any vertex.
A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1.
Example 5:
Find the level of each vertex in the rooted tree shown in Figure 8. What is the height of this tree?
Solution:
Figure 8: A rooted tree
The root a is at level 0. Vertices b, j, and k are at level 1. Vertices c, e, f, and l are at level 2.Vertices d,
g, i, m, and n are at level 3. Finally, vertex h is at level 4. Because the largest level of any vertex is 4,
this tree has height 4.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
11
Example 6:
Which of the rooted trees shown in Figure 9 are balanced?
Solution:
Figure 9: Some rooted trees
T1 is balanced, because all its leaves are at levels 3 and 4. However, T2 is not balanced, because it
has leaves at levels 2, 3, and 4. Finally, T3 is balanced, because all its leaves are at level 3.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
12
Spanning Trees:
DEFINITION 1:
Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every vertex
of G.
Example 1:
Find a spanning tree of the simple graph G shown in Figure 1.
Figure 1: The simple graph G
Solution:
The graph G is connected, but it is not a tree because it contains simple circuits. Remove the edge {a,
e}. This eliminates one simple circuit, and the resulting subgraph is still connected and still contains
every vertex of G. Next remove the edge {e, f} to eliminate a second simple circuit. Finally, remove
edge {c, g} to produce a simple graph with no simple circuits. This subgraph is a spanning tree,
because it is a tree that contains every vertex of G. The sequence of edge removals used to produce
the spanning tree is illustrated in Figure 2.
Figure 2: Producing a spanning tree for G by removing edges that form simple circuits
The tree shown in Figure 2 is not the only spanning tree of G. For instance, each of the trees shown
in Figure 3 is a spanning tree of G.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
13
Figure 3: Spanning trees of G
DEFINITION 2:
A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest
possible sum of weights of its edges.
Prim’s Algorithm:
Example 2:
Use Prim’s algorithm to design a minimum-cost communications network connecting all the
computers represented by the graph in Figure 4.
Figure 4: A weighted graph showing monthly lease costs for lines in a computer network
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
14
Solution:
We solve this problem by finding a minimum spanning tree in the graph in Figure 4. Prim’s algorithm
is carried out by choosing an initial edge of minimum weight and successively adding edges of
minimum weight that are incident to a vertex in the tree and that do not form simple circuits. The
edges in color in Figure 5 show a minimum spanning tree produced by Prim’s algorithm, with the
choice made at each step displayed.
Figure 5: A minimum spanning tree for the weighted graph in figure 4
Example 3:
Use Prim’s algorithm to find a minimum spanning tree in the graph shown in figure 6.
Figure 6: A weighted graph
Solution:
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
15
A minimum spanning tree constructed using Prim’s algorithm is shown in Figure 7. The successive
edges chosen are displayed.
Figure 7: A minimum spanning tree produced using prim’s algorithm
Kruskal’s Algorithm:
Example 4:
Use Kruskal’s algorithm to find a minimum spanning tree in the weighted graph shown in figure 6.
Solution:
A minimum spanning tree and the choices of edges at each stage of Kruskal’s algorithm are shown in
figure 8.
Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka
16
Figure 8: A minimum spanning tree produced by kruskal’s algorithm

More Related Content

What's hot

Graphs - CH10 - Discrete Mathematics
Graphs - CH10 - Discrete MathematicsGraphs - CH10 - Discrete Mathematics
Graphs - CH10 - Discrete Mathematics
Omnia A. Abdullah
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
Chuckie Balbuena
 

What's hot (20)

Inner Product Space
Inner Product SpaceInner Product Space
Inner Product Space
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Elements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Functional analysis
Functional analysis Functional analysis
Functional analysis
 
Group Theory and Its Application: Beamer Presentation (PPT)
Group Theory and Its Application:   Beamer Presentation (PPT)Group Theory and Its Application:   Beamer Presentation (PPT)
Group Theory and Its Application: Beamer Presentation (PPT)
 
Isomorphic graph
Isomorphic graphIsomorphic graph
Isomorphic graph
 
Connectivity of graph
Connectivity of graphConnectivity of graph
Connectivity of graph
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
 
Graphs - CH10 - Discrete Mathematics
Graphs - CH10 - Discrete MathematicsGraphs - CH10 - Discrete Mathematics
Graphs - CH10 - Discrete Mathematics
 
Network flows
Network flowsNetwork flows
Network flows
 
Vector algebra
Vector algebra Vector algebra
Vector algebra
 
Spanning trees
Spanning treesSpanning trees
Spanning trees
 
Introduction to Graph Theory
Introduction to Graph TheoryIntroduction to Graph Theory
Introduction to Graph Theory
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
 
Biconnected components (13024116056)
Biconnected components (13024116056)Biconnected components (13024116056)
Biconnected components (13024116056)
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 
Vector space
Vector spaceVector space
Vector space
 
Liner algebra-vector space-2 Algebra of Subspaces
Liner algebra-vector space-2 Algebra of SubspacesLiner algebra-vector space-2 Algebra of Subspaces
Liner algebra-vector space-2 Algebra of Subspaces
 
Group homomorphism
Group homomorphismGroup homomorphism
Group homomorphism
 

Viewers also liked (11)

Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Backtracking
BacktrackingBacktracking
Backtracking
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 

Similar to Euler and hamilton paths

Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
Read Section 11.4, pages 540 ( 547. Type in the answers below .docxRead Section 11.4, pages 540 ( 547. Type in the answers below .docx
Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
makdul
 

Similar to Euler and hamilton paths (20)

trees-and-forest.pdf
trees-and-forest.pdftrees-and-forest.pdf
trees-and-forest.pdf
 
Discrete-Chapter 10 Trees
Discrete-Chapter 10 TreesDiscrete-Chapter 10 Trees
Discrete-Chapter 10 Trees
 
nossi ch 6
nossi ch 6nossi ch 6
nossi ch 6
 
Graph algorithm
Graph algorithmGraph algorithm
Graph algorithm
 
07 trees
07 trees07 trees
07 trees
 
B.TECH Math project
B.TECH Math projectB.TECH Math project
B.TECH Math project
 
Cs6702 2marks rejinpaul
Cs6702 2marks rejinpaulCs6702 2marks rejinpaul
Cs6702 2marks rejinpaul
 
Cs6702 GCC
Cs6702 GCCCs6702 GCC
Cs6702 GCC
 
Chapter 8 ds
Chapter 8 dsChapter 8 ds
Chapter 8 ds
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
discrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptxdiscrete mathematics binary%20trees.pptx
discrete mathematics binary%20trees.pptx
 
DSA IV Unit.pptx
DSA IV Unit.pptxDSA IV Unit.pptx
DSA IV Unit.pptx
 
Cs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answersCs6702 graph theory and applications 2 marks questions and answers
Cs6702 graph theory and applications 2 marks questions and answers
 
trees.pdf
trees.pdftrees.pdf
trees.pdf
 
Relations
RelationsRelations
Relations
 
FCS (graphs).pptx
FCS (graphs).pptxFCS (graphs).pptx
FCS (graphs).pptx
 
Grade 9 Mathematics Module 5 Quadrilaterals (LM)
Grade 9 Mathematics Module 5 Quadrilaterals (LM)Grade 9 Mathematics Module 5 Quadrilaterals (LM)
Grade 9 Mathematics Module 5 Quadrilaterals (LM)
 
binary tree.pptx
binary tree.pptxbinary tree.pptx
binary tree.pptx
 
graph.pptx
graph.pptxgraph.pptx
graph.pptx
 
Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
Read Section 11.4, pages 540 ( 547. Type in the answers below .docxRead Section 11.4, pages 540 ( 547. Type in the answers below .docx
Read Section 11.4, pages 540 ( 547. Type in the answers below .docx
 

More from University of Potsdam

More from University of Potsdam (20)

Computer fundamentals 01
Computer fundamentals 01Computer fundamentals 01
Computer fundamentals 01
 
Workshop on android apps development
Workshop on android apps developmentWorkshop on android apps development
Workshop on android apps development
 
Transparency and concurrency
Transparency and concurrencyTransparency and concurrency
Transparency and concurrency
 
Database System Architecture
Database System ArchitectureDatabase System Architecture
Database System Architecture
 
Functional dependency and normalization
Functional dependency and normalizationFunctional dependency and normalization
Functional dependency and normalization
 
indexing and hashing
indexing and hashingindexing and hashing
indexing and hashing
 
data recovery-raid
data recovery-raiddata recovery-raid
data recovery-raid
 
Query processing
Query processingQuery processing
Query processing
 
Machine Learning for Data Mining
Machine Learning for Data MiningMachine Learning for Data Mining
Machine Learning for Data Mining
 
Tree, function and graph
Tree, function and graphTree, function and graph
Tree, function and graph
 
Sonet
SonetSonet
Sonet
 
Sets in discrete mathematics
Sets in discrete mathematicsSets in discrete mathematics
Sets in discrete mathematics
 
Set in discrete mathematics
Set in discrete mathematicsSet in discrete mathematics
Set in discrete mathematics
 
Series parallel ac rlc networks
Series parallel ac rlc networksSeries parallel ac rlc networks
Series parallel ac rlc networks
 
Series parallel ac networks
Series parallel ac networksSeries parallel ac networks
Series parallel ac networks
 
Relations
RelationsRelations
Relations
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Prim algorithm
Prim algorithmPrim algorithm
Prim algorithm
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
 

Recently uploaded

Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 

Euler and hamilton paths

  • 1. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 1 Euler and Hamilton Paths: DEFINITION 1: An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path in G is a simple path containing every edge of G. Examples 1 and 2 illustrate the concept of Euler circuits and paths. Example 1: Which of the undirected graphs in Figure 1 have an Euler circuit? Of those that do not, which have an Euler path? Figure 1: The undirected graphs G1, G2 and G3 Solution: The graph G1 has an Euler circuit, for example, a, e, c, d, e, b, a. Neither of the graphs G2 or G3 has an Euler circuit. However, G3 has an Euler path, namely, a, c, d, e, b, d, a, b. G2 does not have an Euler path. Example 2: Which of the directed graphs in Figure 2 have an Euler circuit? Of those that do not, which have an Euler path? Figure 2: The directed graphs H1, H2 and H3 Solution: The graph H2 has an Euler circuit, for example, a, g, c, b, g, e, d, f, a. Neither H1 nor H3 has an Euler circuit. H3 has an Euler path, namely, c, a, b, c, d, b, but H1 does not. Theorem 1:
  • 2. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 2 A connected multigraph with at least two vertices has an Euler circuit if and only if each of its vertices has even degree. Theorem 2: A connected multigraph has an Euler path but not an Euler circuit if and only if it has exactly two vertices of odd degree. Example 3: Which graphs shown in Figure 3 have an Euler path? Figure 3: Three undirected graphs Solution: G1 contains exactly two vertices of odd degree, namely, b and d. Hence, it has an Euler path that must have b and d as its endpoints. One such Euler path is d, a, b, c, d, b. Similarly,G2 has exactly two vertices of odd degree, namely, b and d. So it has an Euler path that must have b and d as endpoints. One such Euler path is b, a, g, f, e, d, c, g, b, c, f, d. G3 has no Euler path because it has six vertices of odd degree. DEFINITION 2: A Hamilton circuit in a graph G is a closed path that visits every vertex in G exactly once. Note that an Euler circuit traverses every edge exactly once, but may repeat vertices, while a Hamilton circuit visits each vertex exactly once but may repeat edges. Example 4: Which of the simple graphs in Figure 4 have a Hamilton circuit or, if not, a Hamilton path?
  • 3. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 3 Figure 4: Three simple graphs Solution: G1 has a Hamilton circuit: a, b, c, d, e, a. There is no Hamilton circuit in G2. But G2 does have a Hamilton path, namely, a, b, c, d. G3 has neither a Hamilton circuit nor a Hamilton path. Example 5: Show that neither graph displayed in Figure 5 has a Hamilton circuit. Figure 5: Two graphs that do not have a Hamilton circuit Solution: There is no Hamilton circuit in G because G has a vertex of degree one, namely, e. However, G has a Hamilton path, namely, e,d,a,b,c. Now consider H. Because the degrees of the vertices a, b, d, and e are all two, every edge incident with these vertices must be part of any Hamilton circuit. It is now easy to see that no Hamilton circuit can exist in H, for any Hamilton circuit would have to contain four edges incident with c, which is impossible. H has a Hamilton path: a,b,c,d,e.
  • 4. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 4 Shortest-Path Problems: Dijkstra’s Algorithm: Example 1: Use Dijkstra’s algorithm to find the length of a shortest path between the vertices a and z in the weighted graph displayed in Figure 1(a).
  • 5. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 5 Figure 1: Using Dijkstra’s Algorithm to Find a Shortest Path from a to z. Solution: The steps used by Dijkstra’s algorithm to find a shortest path between a and z are shown in Figure 1.
  • 6. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 6 Introduction to Trees: DEFINITION 1: A tree is a connected undirected graph with no simple circuits. Example 1: Which of the graphs shown in Figure 1 are trees? Figure 1: Example of trees and non-trees Solution: G1 and G2 are trees, because both are connected graphs with no simple circuits. G3 is not a tree because e, b, a, d, e is a simple circuit in this graph. Finally, G4 is not a tree because it is not connected. Forests: forests have the property that each of their connected components is a tree. Figure 2 displays a forest.
  • 7. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 7 Figure 2: Example of a forest DEFINITION 2: 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. Figure 3: A tree and rooted trees formed by designating two different roots. For instance, Figure 3 displays the rooted trees formed by designating a to be the root and c to be the root, respectively, in the tree T. Tree Terminology: Suppose that T is a rooted tree. If v is a vertex in T other than the root, the parent of v is the unique vertex u such that there is a directed edge from u to v. When u is the parent of v, v is called a child of u. Vertices with the same parent are called 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 descendants of a vertex v are those vertices that have v as an ancestor. A vertex of a rooted tree is called a leaf if it has no children. Vertices that have children are called internal vertices. If a is a vertex in a tree, the subtree with a as its root is the subgraph of the tree consisting of a and its descendants and all edges incident to these descendants.
  • 8. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 8 Example 2: In the rooted tree T (with root a) shown in Figure 4, find the parent of c, the children of g, the siblings of h, all ancestors of e, all descendants of b, all internal vertices, and all leaves. What is the subtree rooted at g? Figure 4: A rooted tree T Solution: The parent of c is b. The children of g are h, i, and j. The siblings of h are i and j. The ancestors of e are c, b, and a. The descendants of b are c, d, and e. The internal vertices are a, b, c, g, h, and j. The leaves are d, e, f , i, k, l, and m. The subtree rooted at g is shown in Figure 5. Figure 5: The subtree rooted at g DEFINITION 3:
  • 9. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 9 A rooted tree is called an m-ary tree if every internal vertex has no more than m children. The tree is called a full m-ary tree if every internal vertex has exactly m children. An m-ary tree with m = 2 is called a binary tree. Example 3: Are the rooted trees in Figure 6 full m-ary trees for some positive integer m? Solution: Figure 6: Four rooted trees T1 is a full binary tree because each of its internal vertices has two children. T2 is a full 3-ary tree because each of its internal vertices has three children. In T3 each internal vertex has five children, so T3 is a full 5-ary tree. T4 is not a full m-ary tree for any m because some of its internal vertices have two children and others have three children. Example 4: What are the left and right children of d in the binary tree T shown in Figure 7(a)? What are the left and right subtrees of c? Solution: Figure 7: A binary tree T and left and right subtrees of the vertex c
  • 10. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 10 The left child of d is f and the right child is g. We show the left and right subtrees of c in Figures 7(b) and 7(c), respectively. More about trees: The level of a vertex v in a rooted tree is the length of the unique path from the root to this vertex. The level of the root is defined to be zero. The height of a rooted tree is the maximum of the levels of vertices. In other words, the height of a rooted tree is the length of the longest path from the root to any vertex. A rooted m-ary tree of height h is balanced if all leaves are at levels h or h − 1. Example 5: Find the level of each vertex in the rooted tree shown in Figure 8. What is the height of this tree? Solution: Figure 8: A rooted tree The root a is at level 0. Vertices b, j, and k are at level 1. Vertices c, e, f, and l are at level 2.Vertices d, g, i, m, and n are at level 3. Finally, vertex h is at level 4. Because the largest level of any vertex is 4, this tree has height 4.
  • 11. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 11 Example 6: Which of the rooted trees shown in Figure 9 are balanced? Solution: Figure 9: Some rooted trees T1 is balanced, because all its leaves are at levels 3 and 4. However, T2 is not balanced, because it has leaves at levels 2, 3, and 4. Finally, T3 is balanced, because all its leaves are at level 3.
  • 12. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 12 Spanning Trees: DEFINITION 1: Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every vertex of G. Example 1: Find a spanning tree of the simple graph G shown in Figure 1. Figure 1: The simple graph G Solution: The graph G is connected, but it is not a tree because it contains simple circuits. Remove the edge {a, e}. This eliminates one simple circuit, and the resulting subgraph is still connected and still contains every vertex of G. Next remove the edge {e, f} to eliminate a second simple circuit. Finally, remove edge {c, g} to produce a simple graph with no simple circuits. This subgraph is a spanning tree, because it is a tree that contains every vertex of G. The sequence of edge removals used to produce the spanning tree is illustrated in Figure 2. Figure 2: Producing a spanning tree for G by removing edges that form simple circuits The tree shown in Figure 2 is not the only spanning tree of G. For instance, each of the trees shown in Figure 3 is a spanning tree of G.
  • 13. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 13 Figure 3: Spanning trees of G DEFINITION 2: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible sum of weights of its edges. Prim’s Algorithm: Example 2: Use Prim’s algorithm to design a minimum-cost communications network connecting all the computers represented by the graph in Figure 4. Figure 4: A weighted graph showing monthly lease costs for lines in a computer network
  • 14. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 14 Solution: We solve this problem by finding a minimum spanning tree in the graph in Figure 4. Prim’s algorithm is carried out by choosing an initial edge of minimum weight and successively adding edges of minimum weight that are incident to a vertex in the tree and that do not form simple circuits. The edges in color in Figure 5 show a minimum spanning tree produced by Prim’s algorithm, with the choice made at each step displayed. Figure 5: A minimum spanning tree for the weighted graph in figure 4 Example 3: Use Prim’s algorithm to find a minimum spanning tree in the graph shown in figure 6. Figure 6: A weighted graph Solution:
  • 15. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 15 A minimum spanning tree constructed using Prim’s algorithm is shown in Figure 7. The successive edges chosen are displayed. Figure 7: A minimum spanning tree produced using prim’s algorithm Kruskal’s Algorithm: Example 4: Use Kruskal’s algorithm to find a minimum spanning tree in the weighted graph shown in figure 6. Solution: A minimum spanning tree and the choices of edges at each stage of Kruskal’s algorithm are shown in figure 8.
  • 16. Gazi Zahirul Islam, Assistant Professor, Department of CSE, Daffodil International University, Dhaka 16 Figure 8: A minimum spanning tree produced by kruskal’s algorithm