Download presentation
Presentation is loading. Please wait.
1
Graphs CS 2606
2
Topics Graph notation revisited More graph problems Undirected graph
Weighted/labeled graph More graph problems Euler Tour Hamiltonian cycle Max Clique Traveling salesman Graphs Slide 2
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 Graphs Slide 3
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 Graphs Slide 4
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) = 20 w(a,d) = w(d,a) = 65 w(b,c) = w(c,b) = 32 w(b,d) = w(d,b) = 12 w(b,e) = w(e,b) = 35 for all other vertex pairs: w(x,y) = 0 if x = y else, w(x,y) = infinity a 20 35 e b 12 32 c 65 d Graphs Slide 5
6
Graph problems Euler tour Hamiltonian cycle Max Clique
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) Graphs Slide 6
7
Graph problems 2 Shortest Paths Minimum Cost Spanning Tree
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 Graphs Slide 7
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 Graphs Slide 8
9
f,c,d and e have odd degree
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 Graphs Slide 9
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 Graphs Slide 10
11
hamiltonian cycle: a,b,c,d,f,e,(then back to a)
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) Graphs Slide 11
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 an NP-complete (intractable) problem No algorithm that performs better (than the exhaustive algorithm) is known Graphs Slide 12
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 Graphs Slide 13
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 Graphs Slide 14
15
w,x,y,z,w – length: 34 y,w,x,z,y – length: 36 z,w,y,x,z – length: 28
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: 34 y,w,x,z,y – length: 36 z,w,y,x,z – length: 28 4 10 14 y 3 7 z x 11 Graphs Slide 15
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 Graphs Slide 16
17
More on NP-Completeness
See chapter 15 of the textbook Graphs Slide 17
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.