1 / 17

Graphs

Graphs. CS 2606. Topics. Graph notation revisited Undirected graph Directed graph Weighted/labeled graph More graph problems Euler Tour Hamiltonian cycle Max Clique Traveling salesman. Undirected Graph. Graph G=(V,E): V={a,b,c,d}, E={(a,b),(b,c),(b,d),(a,d)}. a. b. c. d.

Download Presentation

Graphs

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. Graphs CS 2606

  2. Topics • Graph notation revisited • Undirected graph • Directed graph • Weighted/labeled graph • More graph problems • Euler Tour • Hamiltonian cycle • Max Clique • Traveling salesman

  3. Undirected Graph Graph G=(V,E): V={a,b,c,d}, E={(a,b),(b,c),(b,d),(a,d)} a b c d

  4. Directed Graph Edge set is a set of ordered pairs Graph G=(V,E): V={a,b,c,d}, E={(a,b),(b,c),(b,d),(d,b),(d,a)} a b c d

  5. Weighted Graph Graph G=(V,E,w): V={a,b,c,d,e}, E={(a,b),(a,d),(b,c),(b,d),(b,e)},w: function that maps vertex-pairs to values (can be stored in adjacency matrix) w(a,b) = w(b,a) = 20w(a,d) = w(d,a) = 65w(b,c) = w(c,b) = 32w(b,d) = w(d,b) = 12w(b,e) = w(e,b) = 35 for all othervertex pairs:w(x,y) = 0 if x = yelse, w(x,y) = infinity a 20 35 e b 12 32 c 65 d

  6. Graph problems • Euler tour • Find a sequence of vertices that traverse all edges in the graph exactly once • Hamiltonian cycle • Find a simple cycle that connects all vertices in the graph • Max Clique • Find the largest subset of vertices that are all pair-wise adjacent (connected by an edge)

  7. Graph problems 2 • Shortest Paths • Section 11.4 of textbook • Minimum Cost Spanning Tree • Section 11.5 of textbook • Traveling Salesman • Given a weighted graph G, find the shortest (minimum-length) cycle that contains all vertices in G

  8. Euler Tour • Euler Tour/Cycle: sequence of vertices that traverse all edges exactly once c d a b f e Euler tour: c,d,f,e,a,b,e,c

  9. Euler Tour (2) • Some graphs do not have euler tours • specifically those with vertices whose degree (# of neighbors) is odd c a b d e g f f,c,d and e have odd degree

  10. Euler Tour (3) • There is a straightforward algorithm that obtains an euler tour of a graph, if one such tour exists • Algorithm sketch • Start with any vertex; traverse edges by repeatedly visiting neighbors without repeating an edge • Repeat process, combining the partial tours as you go, until all edges are exhausted

  11. Hamiltonian Cycle • Hamiltonian cycle: simple cycle containing all vertices w c a b z d x y f e no hamiltonian cycle hamiltonian cycle:a,b,c,d,f,e,(then back to a)

  12. Hamiltonian Cycle (2) • Exhaustive (inefficient) algorithm that finds a hamiltonian cycle if one such cycle exists: • Consider all permutations of the vertices • Return the permutation that forms a cycle • An O( n! n ) algorithm • Hamiltonian cycle is an example of anNP-complete (intractable) problem • No algorithm that performs better(than the exhaustive algorithm) is known

  13. Max Clique • Clique: subset of vertices that are all connected by an edge Clique examples: {a,b,e}{e,g}{b,c,d,f} Max-clique:{b,c,d,f} c a b d e f g h

  14. Max Clique (2) • Exhaustive algorithm for Max Clique: • Consider all subsets of vertices • Determine if the subset is a clique • Return the clique with the largest size • An O( 2n n2 ) algorithm • Max Clique is also NP-Complete

  15. Traveling Salesman • Find shortest tour of all vertices (may impose that the salesman end where he started) w Sample tours w,x,y,z,w – length: 34y,w,x,z,y – length: 36z,w,y,x,z – length: 28 4 10 14 y 3 7 z x 11

  16. Traveling Salesman (2) • O( n! n ) algorithm: • Consider all permutations • Compute resulting length for each permutation • Return the permutation that yields the shortest length • Traveling salesman is also NP-complete

  17. More on NP-Completeness • See chapter 15 of the textbook

More Related