Download presentation
Presentation is loading. Please wait.
Published byBarry Wilkerson Modified over 9 years ago
1
Foundations of Discrete Mathematics Chapters 9 and 10 By Dr. Dalia M. Gil, Ph.D.
2
Graphs Graphs are discrete structures consisting of vertices and edges that connect these vertices.
3
Graphs A graph is a pair (V, E) of sets, V nonempty and each element of E a set of two distinct elements of V. The elements of V are called vertices; the elements of E are called edges.
4
Graphs If e is an edge, then e = {v, w}, where v and w are different elements of set V called the end vertices of ends of e. The vertices v and w are said to be incident with the edge vw. The edge vw is incident with each vertex.
5
Graphs Two vertices are adjacent if they are the end vertices of an edge. Two vertices are adjacent if they have a vertex in common. The number of edges incident with a vertex v is called the degree of that vertex and is denoted deg v.
6
Graphs If deg v is an even number, then v is said to be an even vertex. If deg v is an odd number, then v is odd vertex. A vertex of degree 0 is said to be isolated.
7
Subgraph A graph G 1 is a subgraph of another graph G if and only if the vertex and edge sets of G 1 are, respectively, subsets of the vertex and edge sets of G.
8
Example: Subgraph A graph G and three subgraphs G 1, G 2, and G 3 “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 290
9
A Bipartite Graph A bipartite graph is one whose vertices can be partitioned into two (disjoint) sets V 1 and V 2, called bipartition sets in such a way that every edge joins a vertex in V 1 and a vertex in V 2.
10
A Bipartite Graph The complete bipartite graph on bipartition sets of m vertices and n vertices, respectively, is denoted K m,n.
11
Bipartite Graphs Three bipartite graphs, two of which are not complete. No two top vertices are adjacent, and no two bottom vertices are adjacent. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 291
12
Euler The sum of the degrees of the vertices of a pseudograph is an even number equal to twice the number of edges. In symbols, if G(V, E) is a pseudograph, then deg v = 2 |E| vV
13
Example: Euler The graph has 8 vertices of degree 3 deg v = 8(3) = 24 =2|E| vV it must have 12 edges. “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 291
14
Graphs There are several different types of graphs that differ with respect to the kind and number of edges that connect a pair of vertices. Many real problems can be solved using graph models.
15
Types of Graphs Simple graph. Multigraph. Pseudograph. Directed graph. Direct multigraph.
16
A Simple Graph A simple graph G = (V, E) consists of V, a nonempty set of vertices, and E, a set of unordered pairs of distinct elements of V (edges).
17
Example of a Simple Graph A computer network that represents computers (vertices) and telephone lines (undirected edges) that connect two distinct vertices. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 538
18
A Multigraph A multigraph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f (from E to {{u, v} | u, v V, u ≠ v}). The edges e 1 and e 2 are called multiple or parallel edges if f(e 1 ) = f(e 2 ).
19
Example of a Multigraph This graph consist of vertices and undirected edges between these vertices with multiple edges between pairs of vertices allowed (two or more edges may connect the same pair of vertices). “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 538
20
A Pseudograph A pseudograph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f (from E to {{u, v} | u, v V}). An edge is a loop if f (e) = {u, v} = {u}
21
Example of a Pseudograph A computer network may contain vertices with loops, which are edges from a vertex to itself. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 539
22
A Direct Graph A direct graph (V, E) consists of a set of vertices V and a set of edges E that are ordered pairs of elements of V.
23
Example of a Direct Graph A network may not operate in both directions. In this case an arrow pointing from u to v to indicate the direction of the edge (u, v) is used. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 539
24
A Directed Multigraph A directed multigraph G = (V, E) consists of a set V of vertices, a set E of edges, and a function f (from E to {(u, v) | u, v V}). The edges e 1 and e 2 are multiple edges if f(e 1 ) = f(e 2 ).
25
Example of a Directed Multigraph The algorithm uses a finite number of steps, since it terminates after all the integers in the sequence have been examined. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 540
26
Graph Terminology “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 540 TypeEdgesMultiple Edges Allowed? Loops Allowed? Simple GraphUndirectedNo MultigraphUndirectedYesNo PseugographUndirectedYes Directed GraphDirectedNoYes Directed MultigraphDirectedYes
27
Niche Overlap Graphs in Ecology The competition between species in an ecosystem can be modeled using a niche overlap graph. Each species is represented by a vertex.
28
Niche Overlap Graphs in Ecology An undirected edge connects two vertices if the two species represented by these vertices compete. Two species are connected if the food resources they use are the same. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 541
29
Acquaintanceship Graph To represent whether two people know each other (whether they are acquainted) Each person is represented by a vertex. An undirected edge connects two people when they know each other. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 541
30
Influence Graph In studies of group behavior it is observed that certain people can influence the thinking of others. A directed graph can model this behavior. Each person is represented by a vertex. There is a directed vertex from vertex a to vertex b when person a influences person b.
31
Influence Graph (A Directed Graph) Deborah can influence Brian, Fred, and Linda, but no one can influence her. Yvonne and Brian can influence each other. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 542
32
Round-Robin Tournaments A tournament where each team plays each other team exactly once is called a round-robin tournament. In this case a directed graph is used. Each team is represented by a vertex.
33
Round-Robin Tournaments (a, b) is an edge if team a beats team b. Team 1 is undefeated in this tournament Team 3 is winless. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 542
34
Call Graphs Graphs can be used to model telephone calls made in a network, such as a long- distance telephone network. A directed multigraph can be used. Each telephone is a vertex Each telephone call is represented by a directed edge.
35
Call Graph using Directed Graph Three calls have been made from 732-555-1234 to 732-555-9876 and two in the other direction. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 542
36
Call Graph using Directed Graph One call has been made from 732-555-4444 to 732-555-0011. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 542
37
Call Graph using Undirected Graph An undirected graph is used if there has been a call connecting two telephone numbers. Each edge tells us whether there has been a call between two numbers. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 542
38
Precedence Graph and Concurrent Processing Computer programs can be executed more rapidly by executing certain statements concurrently. It is important not to execute a statement that requires results of statement not yet executed.
39
Precedence Graph and Concurrent Processing The dependence of statements on previous statements can be represented by a directed graph. There is an edge from one vertex to a second vertex if the statement represented by the second vertex cannot be executed before the statement represented by the first vertex has been executed.
40
Precedence Graph and Concurrent Processing In this section of a computer program the statement S 5 cannot be executed before S 1, S 2, and S 4 are executed. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 543
41
Representing Graphs 1.To represent a graph without multiple edges is to list all the edges of this graph. 2.To represent a graph with no multiple edges is to use adjacent list, which specify the vertices that are adjacent to each vertex of the graph.
42
Example: Representing Graphs Use adjacent lists to describe the simple graph given in the figure. VertexAdjacent Vertices ab, c, e ba ca, d, e dc, e ea, c, d “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 557
43
Example: Representing Graphs Represent the directed graph shown in the figure by listing all the vertices that are the terminal vertices of edges starting at each vertex of the graph in the figure. Initial Vertex Terminal Vertices ab, c, d, e bb, d ca, c, e d eb, c, d “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 558
44
The Adjacency Matrix A (A G ) If A = {a ij } is the adjacency matrix A of G, then a ij = 1 if {v i, v j } is an edge of G and a ij = 0 otherwise. The adjacency matrix of a simple graph is symmetric if a ij = a ji. A simple graph has no loops, so each entry a ii = 1, 2, …, n is 0.
45
Example: Adjacent Matrix Use an adjacent matrix to represent the graph. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 558
46
Example: Adjacent Matrix Draw a graph with the adjacent matrix with respect to ordering of vertices a, b, c, d. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 559
47
Example: Adjacent Matrix Use an adjacent matrix to represent the pseudograph shown in the figure. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 559
48
Incidence Matrices Let G = (V, E) be an undirected graph. Suppose that v 1,v 2, …, v n are the vertices and e 1, e 2, …, e m are the edges of G. Then the incidence matrix with respect to this ordering of V and E is n x m matrix M = {m ij }, where m ij = 1 when edge e i is incident with v i, m ij = 0 otherwise
49
Represent the graph with an incidence matrix. Example: Incidence Matrix “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 560
50
Represent the pseudograph with an incidence matrix. Example: Incidence Matrix “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 560
51
We often need to know whether it is possible to draw two graph in the same way. Isomorphism of Graphs In chemistry different compounds can have the same molecular formula but can differ in structure. Such compounds will be represented by graph that cannot be drawn in the same way.
52
The simple graphs G 1 = (V 1, E 1 ) and G 2 = (V 2, E 2 ) are isomorphic if there is a one-to-one and onto function f from V 1 to V 2, a and b are adjacent in G 1 if and only if f(a) and f(b) are adjacent in G 2, for all a and b in V 1. Isomorphism of Graphs
53
Two simple graphs are isomorphic, if there is a one-to-one correspondence between vertices of the two graphs that preserves the adjacency relationship. Isomorphism of simple graph is an equivalence relation. Isomorphism comes from the Greek root isos for “equal” and morphe for “form.” Isomorphism of Graphs
54
Show that the graphs G = (V, E) and H = (W, F) are isomorphic Example: Isomorphism f(u 1 )= v 1, f(u 2 )= v 4, f(u 3 )= v 3, f(u 4 )= v 2 “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561 There is a one-to-one correspondence between V and W.
55
Show that the graphs G = (V, E) and H = (W, F) are isomorphic Example: Isomorphism (cont.) The adjacent vertices in G are u 1 and u 2, u 1 and u 3, u 2 and u 4, u 3 and u 4 “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
56
Show that the graphs G = (V, E) and H = (W, F) are isomorphic Example: Isomorphism (cont.) Each of the pairs f(u 1 )= v 1 and f(u 2 )= v 4 f(u 1 )= v 1 and f(u 3 )= v 3 f(u 2 )= v 4 and f(u 4 )= v 2 f(u 3 )= v 3 and f(u 4 )= v 2 are adjacent in H. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
57
Two simple graphs are not isomorphic, if they do not share a property that isomorphic simple graphs must both have. This property is called an invariant with respect to isomorphism of simple graph. Isomorphism of Graphs
58
Isomorphic simple graphs must have the same number of vertices, since there is a one-to-one correspondence between the sets of vertices of the graphs. Isomorphism: Some Invariants
59
Isomorphic simple graphs must have the same number of edges, because the one-to-one correspondence between vertices establishes a one-to-one correspondence between edges. Isomorphism of Graphs
60
The degree of the vertices in isomorphic simple graph must be the same. A vertex v of degree d in G must correspond to a vertex f(v) of degree d in H, since a vertex w in G is adjacent to v if and only if f(v) and f(w) are adjacent in H. Isomorphism of Graphs
61
Show that the graphs are not isomorphic. Examples of Graphs not Isomorphic G and H have 5 vertices and 6 edges H has a vertex of degree one (e). G has no vertices of degree one. G and H are not isomorphic. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
62
Determine whether the graphs are isomorphic. Examples of Graphs not Isomorphic G and H have 8 vertices and 10 edges. G and H have 4 vertices of degree 2 and 4 of degree 3. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
63
Determine whether the graphs are isomorphic. Examples of Graphs not Isomorphic In G deg(a) = 2, and a must correspond to either t, u, x, or y in H. t, u, x, and y are adjacent to another vertex of degree 2, which is not true for a in G. G and H are not isomorphic. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
64
Determine whether the graphs are isomorphic using subgraphs. Examples of Graphs not Isomorphic In G deg(a) = 2, and a must correspond to either t, u, x, or y in H. t, u, x, and y are adjacent to another vertex of degree 2, which is not true for a in G. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 561
65
Determine whether the graphs are isomorphic using subgraphs. Examples of Graphs not Isomorphic “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 562
66
Determine whether the graphs are isomorphic using subgraphs. Examples of Graphs not Isomorphic The subgraphs of G and H made up of vertices of degree 3 and the edges connecting then must be isomorphic if these two graphs are isomorphic. G and H are not isomorphic. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 562
67
Determine whether the graphs are isomorphic using adjacency matrix. Examples of Graphs Isomorphic Both G and H have 6 vertices and 7 edges. Both have four vertices of degree 2 and 2 vertices of degree three. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 562
68
Determine whether the graphs are isomorphic using adjacency matrix. Examples of Graphs Isomorphic “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pp 562-563
69
Determine whether the graphs are isomorphic using adjacency matrix. Examples of Graphs Isomorphic “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pp 562-563
70
Determine whether the graphs are isomorphic using adjacency matrix. Examples of Graphs Isomorphic A G = A H, G and H are isomorphic. “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. p 563
71
A path is a sequence of edges that begins at a vertex of a graph and travels along edges of the graph, always connecting pairs of adjacent vertices. Path
72
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. Walk
73
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. Walk
74
A trail is a walk in which all edges are distinct; A path is a walk in which all vertices are distinct. Trail
75
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. Circuit
76
Terms and their characteristics TermCharacteristics TrailDistinct edges PathDistinct vertices CircuitClosed trail CycleClosed trail with distinct vertices (hence distinct edges too)
77
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, 2006. pag 305
78
Example Trail : A B C E F C D (distinct edges) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 305
79
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, 2006. pag 305
80
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, 2006. pag 305
81
Example 3-cycle : B C D B “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 305
82
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, 2006. pag 305
83
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. An Eulerian or Euler Circuit
84
The graph G 1 has an Euler circuit: a, e, c, d, e, b, a Example: An Eulerian Circuit “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 578
85
The graph G 2 and G 3 don’t have an Euler circuit. G 3 has an Euler path: a, c, d, e, b, d, a, b G 2 does not have an Euler path. Example: An Eulerian Circuit “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 578
86
H 2 has an Euler circuit: a, g, c, b, g, e, d, f, a H 1 nor H 3 has an Euler circuit. H 3 has an Euler path: c, a, b, c, d, b H 1 does not have an Euler path. Example: An Eulerian Circuit “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 579
87
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. An Eulerian Circuit
88
G 1 contains two vertices of odd degree (b and d). b and d must be the end points of this Euler path. Example: Eulerian 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, 2003. pag 582
89
G 2 contains exactly two vertices of odd degree (b and d). b and d must be the end points of this Euler path. Example: Eulerian 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, 2003. pag 582
90
G 3 has six vertices of odd degree. G 3 has no Euler path. Example: No Eulerian Path “Discrete Mathematics and its Applications.” Fifth Edition, by Kenneth H. Rosen. Mc Graw Hill, 2003. pag 582
91
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. Hamiltonian Cycles
92
A Hamiltonian circuit is a cycle. The terms Hamiltonian circuit and Hamiltonian cycle are synonymous. Hamiltonian Cycles
93
Cycle A B C D E A is Hamiltonian G 2 is not Hamiltonian G 1 is Hamiltonian “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 311
94
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. Shortest Path Algorithm
95
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. Shortest Path Algorithm
96
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. The Traveling Salesman’s Problem
97
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. The Traveling Salesman’s Problem
98
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. a)For each labeled vertex u(x, d) and for each unlabeled vertex v adjacent to u, compute d+w(e) where e = uv. Dijkstra’s Algorithm
99
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. Dijkstra’s Algorithm
100
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, 2006. pag 328
101
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, 2006. pag 328
102
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, 2006. pag 328
103
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, 2006. pag 328
104
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, 2006. pag 328
105
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, 2006. pag 328
106
To find a shortest path from vertex A to vertex E in a weighted graph. Step 1 Set v 1 = 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: Dijkstra’s Algorithm (Improved)
107
(a)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). (b)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. Dijkstra’s Algorithm (Improved)
108
At the start, A = v 1 is given the permanent label 0, all the others are given temporary label Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
109
Next, H, B, and G have their temporary labels decreased to 5, 7, and 8, respectively, all other temporary labels stay at . Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
110
Since 5 is the minimum of 5, 7, 8, set v 2 = H, The vertices adjacent to v 2. For B, 5 + 4 = 9, 9 > 7, so no change occurs. For G, 5 + 5 = 10, 10 > 8. so no change occurs, set v 3 = B. Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
111
The vertices adjacent to v 3. For C, 7 + 8 = 15. For I, 7 + 3 = 10. Now C, I, and G have their temporary labels 15, 10, 8, respectively. The smallest is 8. so v 4 = G. Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
112
The vertices adjacent to v 4. For I, 8 + 2 = 10, the current label, so there is no change. For F, 8 + 7 = 15, so F gets a temporary label of 15 and set v 5 = I Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
113
Next, we have a choice of C or F for v 6 and J gets a temporary label 17. Assuming v 6 = C, then F = v 7 and D obtains a temporary label 23. Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
114
Finally, v 10 = 21. Then D gets its temporary label lowered to 20 and becomes v 9. Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
115
This algorithm gives the length of the shortest path but not the path itself. Dijkstra’s Algorithm (Improved) “Discrete Mathematics with Graph Theory.” Fifth Edition, by E. G. Goodaire ane M. Parmenter Prentce Hall, 2006. pag 330
116
This algorithm gives the length of the shortest path but not the path itself. (permanent label of v l ) + (weight of edge v l v i ) = (permanent label of v i ) Dijkstra’s Algorithm (Improved)
117
Topics covered Graph. Definitions and basic properties. Adjacency matrices. Isomorphism.
118
Topics covered Path, walk, circuit, and cycle. Eulerian circuits. Hamilton cycles. Shortest path algorithms: Dijkstra’s Algorithm.
119
Reference “Discrete Mathematics with Graph Theory”, Third Edition, E. Goodaire and Michael Parmenter, Pearson Prentice Hall, 2006. pp 281-303.
120
Reference “Discrete Mathematics and Its Applications”, Fifth Edition, Kenneth H. Rosen, McGraw- Hill, 2003. pp 281-567.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.