Download presentation
Presentation is loading. Please wait.
1
Foundations of Discrete Mathematics
Chapter 10 By Dr. Dalia M. Gil, Ph.D.
2
Path A path is a sequence of edges hat begins at a vertex of a graph and travels along edges of the graph, always connecting pairs of adjacent vertices.
3
Walk A walk in a pseudograph is an altering sequence of vertices and edges, beginning and ending with a vertex, in which each edge is incident with the vertex immediately preceding it and the vertex immediately following it.
4
Walk The length of a walk is the number of edges in it.
A walk is closed if the first vertex is the same as the last and otherwise open.
5
Trail A trail is a walk in which all edges are distinct; a path is a walk in which all vertices are distinct.
6
Circuit A closed trail is a circuit.
A circuit in which the first vertex appears exactly twice (at the beginning and the end) and in which no other vertex appears more than once is a cycle. An n-cycle is a cycle with n vertices. It is even if n is even and odd if n is odd.
7
Terms and their characteristics
Trail Distinct edges Path Distinct vertices Circuit Closed trail Cycle Closed trail with distinct vertices (hence distinct edges too)
8
Example Walk : A B C E F C B D (length : 7)
“Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
9
Example Trail : A B C E F C D
“Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
10
Example Closed walk : A B C E F C B D A
“Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
11
Example Circuit : B C E F C D B
“Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
12
Example 3-cycle : B C D B “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
13
Example A closed walk (not a cycle): C E F C B D C
“Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 305
14
An Eulerian Circuit An Eulerian or 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.
15
Example: An Eulerian Circuit
The graph G1 has an Euler circuit: a, e, c, d, e, b, a “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 578
16
Example: An Eulerian Circuit
The graph G2 and G3 don’t have an Euler circuit. G3 has an Euler path: a, c, d, e, b, d, a, b G2 does not have an Euler path. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 578
17
Example: An Eulerian Circuit
H2 has an Euler circuit: a, g, c, b, g, e, d, f, a H1 nor H3 has an Euler circuit. H3 has an Euler path: c, a, b, c, d, b H1 does not have an Euler path. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 579
18
An Eulerian Circuit A connected multigraph has an Eulerian circuit if and only if each of its vertices has even degree. A connected multigraph has an Eulerian path but not an Eulerian circuit if and only if it has exactly two vertices of odd degree.
19
Example: Eulerian Path
G1 contains two vertices of odd degree (b and d). b and d must be the end points of this Euler path. d, a, b, c, d, b is an Euler path. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 582
20
Example: Eulerian Path
G2 contains exactly two vertices of odd degree (b and d). b and d must be the end points of this Euler path. b, a, g, f, e, d, c, g, b, c, f, d is an Euler path. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 582
21
Example: No Eulerian Path
G3 has six vertices of odd degree. G3 has no Euler path. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, pag 582
22
Hamiltonian Cycles A Hamiltonian cycle in a graph is a cycle that contains every vertex of a graph. A Hamiltonian graph is one with a Hamiltonian cycle. A Hamiltonian circuit as a circuit in which every vertex except the first and last appears exactly once.
23
Hamiltonian Cycles A Hamiltonian circuit is a cycle.
The terms Hamiltonian circuit and Hamiltonian cycle are synonymous.
24
Hamiltonian Cycles G1 is Hamiltonian G2 is not Hamiltonian
Cycle A B C D E A is Hamiltonian “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 311
25
Shortest Path Algorithm
Many problems can be modeled using graphs with weights to their edges. Problems associated with edge is a unit of time, distance, cost, or capacity in some sense.
26
Shortest Path Algorithm
A weighted graph is a graph G(V, E) together with a function w: E → [0, ). If e is an edge, the nonnegative real number w(e) is called the weight of e. The weight of a subgraph of G (often a path or a trail) is the sum of the weights of the edges of the subgraph.
27
The Traveling Salesman’s Problem
A traveling salesman visits various towns and cities. If he wants to avoid having to pass through the same community twice, he needs a Hamiltonian cycle through the map of towns and air routs.
28
The Traveling Salesman’s Problem
A traveling salesman visits various towns and cities. If he wants to avoid having to pass through the same community twice, he needs a Hamiltonian cycle through the map of towns and air routs.
29
Dijkstra’s Algorithm To find a shortest path from vertex A to vertex E in a weighted graph. Step 1 Assign to A the label (_, 0). Step 2 Until E or no further labels can be assigned, do the following. For each labeled vertex u(x, d) and for each unlabeled vertex v adjacent to u, compute d+w(e) where e = uv.
30
Dijkstra’s Algorithm b) Find the minimum value d’ of all numbers d + w(e) found in a). c) For each u and v for which d + w(e) = d’, assign to v the label (u, d’). If a vertex can be labeled (x, d’) for various vertices x, make any choice.
31
Example: Dijkstra’s Algorithm
Give A the label (_, 0). There are 3 edges incident with A with weights 7, 5, and 8. d = 0 “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
32
Example: Dijkstra’s Algorithm
Since d = 0, vertex H gives the smallest value of d + w(e), H acquires the label (A, 5), G the label (A, 8), and B the label (A, 7) because they are the smallest d + w(e). “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
33
Example: Dijkstra’s Algorithm
Vertex I and C give the smallest value of d + w(e), I acquires the label (B, 10), and C the label (B, 15) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
34
Example: Dijkstra’s Algorithm
Vertex J, D and F give the smallest value of d + w(e), J acquires the label (I, 17), D the label (J, 20), and F the label (D, 15). “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
35
Example: Dijkstra’s Algorithm
Vertex E gives the smallest value of d + w(e), E acquires the label (F, 21). “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
36
Example: Dijkstra’s Algorithm
The shortest route from A to E has weight 21. A shortest path is AGFE. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 328
37
Dijkstra’s Algorithm (Improved)
To find a shortest path from vertex A to vertex E in a weighted graph. Step 1 Set v1 = A and assign to this vertex the permanent label 0. Assign every other vertex a temporary label of , where is a symbol that, by definition, is deemed to be larger that any real number. Step 2 Until E has been assigned a permanent label or no temporary labels are changed in (a) or (b) do the following:
38
Dijkstra’s Algorithm (Improved)
Take the vertex vi that most recently acquired a permanent label, say d. For each vertex v that is adjacent to vi and has not yet received a permanent label, if d + w(vi, v) < t, the current temporary label of v, change the temporary label of v to d + w(vi, v). Take a vertex v that has a temporary label smallest among all temporary labels in the graph. Set vi+1 = v and make its temporary label permanent. If there are several vertices v that tie for smallest temporary label, make any choice.
39
Dijkstra’s Algorithm (Improved)
At the start, A = v1 is given the permanent label 0, all the others are given temporary label “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
40
Dijkstra’s Algorithm (Improved)
Next, H, B, and G have their temporary labels decreased to 5, 7, and 8, respectively, all other temporary labels stay at . “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
41
Dijkstra’s Algorithm (Improved)
Since 5 is the minimum of 5, 7, 8, set v2 = H, The vertices adjacent to v2. For B, = 9, 9 > 7, so no change occurs. For G, = 10, 10 > 8. so no change occurs, set v3 = B. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
42
Dijkstra’s Algorithm (Improved)
The vertices adjacent to v3. For C, = 15. For I, = 10. Now C, I, and G have their temporary labels 15, 10, 8, respectively. The smallest is 8. so v4 = G. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
43
Dijkstra’s Algorithm (Improved)
The vertices adjacent to v4. For I, = 10, the current label , so there is no change. For F, = 15, so F gets a temporary label of 15 and set v5 = I “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
44
Dijkstra’s Algorithm (Improved)
Next, we have a choice of C or F for v6 and J gets a temporary label 17. Assuming v6= C, then F = v7 and D obtains a temporary label 23. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
45
Dijkstra’s Algorithm (Improved)
Finally, v10 = 21. Then D gets its temporary label lowered to 20 and becomes v9. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
46
Dijkstra’s Algorithm (Improved)
This algorithm gives the length of the shortest path but not the path itself. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, pag 330
47
Dijkstra’s Algorithm (Improved)
This algorithm gives the length of the shortest path but not the path itself. (permanent label of vl) + (weight of edge vlvi) = (permanent label of vi)
48
Topics covered Eulerian circuits. Hamilton cycles.
Shortest path algorithms: Dijkstra’s Algorithm.
49
Reference “Discrete Mathematics with Graph Theory”, Third Edition, E. Goodaire and Michael Parmenter, Pearson Prentice Hall, pp
50
Reference “Discrete Mathematics and Its Applications”, Fifth Edition, Kenneth H. Rosen, McGraw-Hill, pp
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.