1 / 34

COMP2012 Discrete Mathematics

COMP2012 Discrete Mathematics. Instructor: Zhijun Wang. HW#3 is due today HW#4 is online now Today’s content: Dijkstra’s shortest-path algorithm Representations of graphs Isomorphisms of graphs Planar graph. Shortest-Path Algorithms.

keisha
Télécharger la présentation

COMP2012 Discrete Mathematics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP2012Discrete Mathematics Instructor: Zhijun Wang HW#3 is due today HW#4 is online now Today’s content: Dijkstra’s shortest-path algorithm Representations of graphs Isomorphisms of graphs Planar graph

  2. Shortest-Path Algorithms One important problem in graph theory is how to find the shortest-path from one vertex to another in a weighted graph. Use w (i, j) represents the weight of the path (i, j). Edsger W. Dijkstra (1930-2002) proposed an algorithm to find the shortest path between any pair of vertices in a weighted graph, called Dijstrak’s shortest-path algorithm. c 4 5 d 8 3 a 4 b

  3. Dijkstra’s shortest-path algorithm The algorithm finds the length of a shortest path from vertex a to vertex z in a connected, weighted graph. The weight of edge (i, j) is w(i, j) > 0 and the label of vertex x is L(x). At the termination, L(z) is a shortest path from a to z. Input: A connected, weighted graph in which all weights are positive; vertices a and z Output: L(z), the length of a shortest path from a to z.

  4. Dijkstra’s shortest-path algorithm • Dijkstra (w, a, z, L){ • L(a) = 0 • for all vertices x  a • L(x) =  • T = set of all vertices • // T is the vertices whose shortest distance • // from a has not been found • while (z  T ) { • choose v T with minimum L (v) • T = T - {v} • for each x  T adjacent to v • L(x) = min{L(x), L(v)+w(v,x)} • } • }

  5. Example of Dijkstra’s algorithm b 2 c 1 2 4 3 2 e z a d 4 Find the shortest path from a to z 7 3 6 1 5 g f b  L(a) is the permanent length, others are temporary c  1 2 4 3 0 2  e z a d   4 7 3 T={b, c, d, e, f, g, z} 6 1  5 g f 

  6. Example of Dijkstra’s algorithm b 2  c Consider all edges incident to a, update the length of vertices adjacent to a, using L(x)=min (L(x), L(a)+w(a,x)}. 2  1 2 4 3 0 2 z e a d   4  7 3 6 f has the minimal length in temporary vertices.Choose f to be permanent. Remove f from T. T={b, c, d, e, g, z} 1   1 5 g f b  c 2 1 2 4 3 0 2  e z Mark b as permanent Remove b from T, T={c, d, e, g, z} a  4 d  4 7 3 6 1  1 5 g 6 f

  7. Example of Dijkstra’s algorithm b 2 c 2 4 Mark c as permanent and Remove c from T T={ d, e, g, z}  1 2 4 3 5 0 2 e z  a 6 4 d 4  7 3 6 Mark d as permanent Remove d from T, T={e, g, z} 1 6 1 5 g f b 4 c 2 1 2 4 3 When L(z) becomes permanent, we find the shortest path L(z), here L(z) = 5 0 2 e z a 4 d 6 5 4 7 3 6 1 1 5 g 6 f

  8. Matrix representation of Dijkstra’s shortest-path algorithm b 2 c (1) a b c d e f g z a ( 0        ) 1 2 4 3 2 e z a d 4 7 (2) (a) b c d e f g z a ( 0 2    1   ) 3 6 1 5 g f (3) (a) b c d e (f) g z a ( 0 2  4  1 6  ) L(x)=min(L(x), L(v)+w(x,v)) (4) (a) (b) c d e (f) g z a ( 0 2 4 4 6 1 6  ) (5) (a) (b) (c) d e (f) g z a ( 0 2 4 4 6 1 6 5 ) (6) (a) (b) (c) (d) e (f) g z a ( 0 2 4 4 6 1 6 5 ) (7) (a) (b) (c) (d) e (f) g (z) a ( 0 2 4 4 6 1 6 5 ) L(z) =5

  9. Find the shortest-path of a graph b 3 c (1) a b c d e z a ( 0      ) (a - - - - - ) b, 5 a,2 2 2   0 1 z a e,4  (2) (a) b c d e z a ( 0 2  1   ) (a a - a - - ) 3 L(z) = 4 a,1  2  d, 2 1 1 e d Path (a, d, e, z) (3) (a) b c (d) e z a ( 0 2  1 2  ) (a a - a d - ) (4) (a) (b) c (d) e z a ( 0 2 5 1 2  ) (a a b a d - ) (6) (a) (b) c (d) (e) (z) a ( 0 2 5 1 2 4 ) (a a b a d e ) (5) (a) (b) c (d) (e) z a ( 0 2 5 1 2 4 ) (a a b a d e ) L(z)=4 and path (a, d, e, z)

  10. Representation of graphs b c Adjacency matrix a b c d e a ( ) a b c d e 0 1 0 0 1 1 0 1 0 1 0 1 2 0 1 0 0 0 0 2 1 1 1 2 0 e d The value of the (i,j) entry is the number of edges from vetex i to vetex j.

  11. More example on a simple graph b Adjacency matrix a b c d e a ( ) c a b c d e 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 e d What is the usefulness of adjacency matrix?

  12. Theorem Theorem: If A is the adjacency matrix of a simple graph, the ij-th entry of An is equal to the number of paths of length n from vertex i to vertex j, n=1, 2, …. The theorem can be proven by mathematical induction

  13. Application of the theorem-I b Adjacency matrix a b c d e a b c d e ( ) a 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 c A= e d a b c d e ) ( ) ( ) ( 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 a b c d e 2 0 2 0 1 0 3 1 2 1 2 1 3 0 1 0 2 0 2 1 1 1 1 1 2 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 1 1 0 0 A2 = =

  14. Application of the theorem-I b a b c d e ( ) a b c d e 2 0 2 0 1 0 3 1 2 1 2 1 3 0 1 0 2 0 2 1 1 1 1 1 2 A2 = a c e d There are 2 paths from a to a with length 2, a-b-a, a-d-a There are zero path from a to b with length 2 There are 2 paths from a to c with length 2, a-b-c, a-d-c There are zero path from a to d with length 2. There are 1 paths from a to e with length 2, a-b-e

  15. Application of the theorem-II b a b c d e ) ( 9 3 11 1 6 3 15 7 11 8 11 7 15 3 8 1 11 3 9 6 6 8 8 6 8 a b c d e A4 =A2A2= a c e d There are 9 paths from a to a with length 4 There are 3 paths from a to b with length 4 There are 11 paths from a to c with length 4 There are 1 path from a to d with length 4. There are 6 paths from a to e with length 4

  16. Excise-1 Give the following graph: (1) Find the shortest path from vetx a to vetex z; (2) Give the adjacencymatrix of the graph; (3) Determine how many paths from vextex d to b with length 2.

  17. Isomorphic graph a A x1 x2 y1 b y2 y4 D e C x3 y3 x5 y5 d x4 c E B G1 G2 Mapping the corresponding vertices and edges from G1 to G2. f={(a, A), (b, B), (c, C), (d, D), (e, E)} g={(x1, y1), (x2, y2), (x3, y3), (x4,y4), (x5,y5)}

  18. Isomorphisms of graphs Graphs G1 and G2 are isomorphic if there is a one-to-one, onto function f from the vertices of G1 to the vertices of G2 and a one-to-one, onto function g from the edges of G1 to the edges of G2, so that an edge e is incident on v and w in G1 if and only if edge g (e) is incident on f(v) and f(w) in G2. The pair of functions f and g is called an isomorphism of G1 and G2.

  19. How to determine isomorphic graphs Theorem :Graphs G1 and G2 are isomorphic if and only if for some ordering of their vertices, their adjacency matrices are equal. Corollary:Let G1 and G2 be simple graphs. The following are equivalent: (1) G1 and G2 are isomorphic. (2) There is a one-to-one, onto function f from the vertex set of G1 to the vertex set of G2 satisfying the following: vertices v and w are adjacent in G1 if and only if the vertices f(v) and f(w) are adjacent in G2.

  20. Matrixes of isomorphic graphs a x1 x2 y1 y2 A y4 b D C The isomorphic graphs have the same matrixes after ordering the vertices. e G1 y3 G2 y5 x3 x5 E B d x4 c a b c d e A B C D E ( ) ( ) 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 1 0 A B C D E 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 1 0 0 1 0 a b c d e

  21. Invariants of isomorphic graphs A property P is an invariant if whenever G1 and G2 are isomorphic graphs: if G1 has property P, G2 also has property P. The isomorphic graphs have same number of vertices, same number of edges. The same number of vertices with same degrees.

  22. Which pair of graphs are isomorphic? d 6 3 a Not isomorphic, different number of vertices e 5 4 G2 c G1 4 (2) 2 3 1 a b h c Not isomorphic, different number of vertices with degree 2 g f 5 6 7 8 d e G4 G3

  23. Which pair of graphs are isomorphic? (3) b a a b 3 c e 5 4 d G6 e c G5 a G5 and G6 are isomorphic G5 can be redrawn as G7 b d G7

  24. Planar graph A graph is planar if it can be drawn in the plane without its edge crossing. K3,3 is not a planar graph K5 is not planar A planar graph

  25. Face A face is characterized by the cycle that forms its boundary. The cycle (a-b-c-d-a) is a face. Cycle (b-c-e-b) is a face, and (a-b-e-c-d-a) forma an out face. There are total 3 faces of the graph. b a c e d

  26. Euler’s formula If G is a connected, planar graph with e edges, v vertices, andffaces, then f = e-v+2 In the graph G, e=6, v=5, f=3, then e-v+2=3=f b a c e G d

  27. More examples on face If G is a connected, planar graph with e edges, v vertices, and f faces, then f = e-v+2 How many faces in G are there? e=8, v=5, then f = e-v+2 = 5 b 5 faces: (a-b-c-a), (b-c-e-b), (a-c-d-a), (c-d-e-c), (a-b-e-d-a) a c e G d

  28. Series reduction If a graph G has a vertex v of degree 2 and edges (v, v1) and (v, v2) with v1  v2, we say that the edges (v, v1) and (v, v2) are in series. A series reduction consists of deleting the vertex v from the graph G and replacing the edge (v, v1) and (v, v2) by the edge (v1, v2) b (b, c) and (c, d) are in series b a Series reduction a c e G2 e d G1 d

  29. Homeomorphic Graphs G1 and G2 are homeomorphic if G1 and G2 can be reduced to isomorphic graphs by performing a sequence of series reductions. G1 and G2 are homeomorphic b b a a c d C G2 e G1 d

  30. Kuratowski’s theorem A graph G is planar if and only if G does not contain a subgraph homeomorphic to K5 or K3,3 a a Is G1 a planar graph? b f b f g Eliminate edges (a, b) and (f,e) g e h h e d c d c G1 G2

  31. Example Is G1 a planar graph? a a b f b f g Eliminate edges (g,h) g e h h e d c d c G2 G3

  32. Example G1 is not planar Is G1 a planar graph? a a b f b f g e h Series reduction e d d c c G3 K3,3

  33. Excise-2 a Are there planar graphs? b a e f b c d f c g h d i j e G1 G2

  34. Questions??

More Related