Talk Graph Algorithms
Talk Graph Algorithms
Graph algorithms
Tran, Van Hoai
Faculty of Computer Science & Engineering HCMC University of Technology E-mail: [email protected] Homepage: http://www.cse.hcmut.edu.vn/hoai
2011-2012
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Notations
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Basic problems
Topological sort Minimum spanning trees Single-source shortest paths All-pair shortest paths Maximum flow Strongly connected components Transitive closure
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
we xe eE xe
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
we xe eE xe
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
MST algorithms
Algorithm 1: Prim
Input: G , r begin ET = ; VT = {r }; while VT = V do (u, v ) = arg mine connected to S {we }; ET = ET {(u, v )}; VT = VT {{u, v } \ S}; end end
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
MST algorithms
Algorithm 3: Prim
Input: G , r begin ET = ; VT = {r }; while VT = V do (u, v ) = arg mine connected to S {we }; ET = ET {(u, v )}; VT = VT {{u, v } \ S}; end end
Algorithm 4: Kruskal
Input: G , r begin ET = ; sort E according to we ; let the ordering be e1 , e2 , . . . , e|E | ; for each edge ei , i = 1, 2, . . . , |E | do if ET {ei } has no cycle then ET = ET {ei }; if |ET | = |V | 1 then break; end end end end
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
= 1 s is source =0 v V =1 d is destination e E
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
= 1 s is source =0 v V =1 d is destination e E
Dijkstra: correct if w : E Z+ Bellman-Ford: suggested for negative-weighted graphs (except that there is no negative loop)
Tran, Van Hoai Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Floyd-Warshall
Recurrence equation
Algorithm 9: Floyd-Warshall
(k) dij
w(i,j) min{dij
(k1)
if k = 0 , dik
(k1)
+ dkj
(k1)
if k 1
=
(k1)
min{dij dkj end end Tran, Van Hoai end end Graph algorithms
(k1)
, dik
(k1)
};
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
xe Z +
eI (v )
bve xe = 0 v V \ {s, d} e E
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
xe Z +
eI (v )
bve xe = 0 v V \ {s, d} e E
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
IP model
max s.t.
v V xv xv + uA(v ) auv xu xv {0, 1}
= 1 v V v V
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
With GNU C/C++ How to run your binary $ mpirun -np <#number of processes> program <graph file> <source vertex> <destination vertex>
graph file: MeTiS format output: sequence of vertices on shortest path, computing time (including data loading time)
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Data: 4elt.graph (2D finite element mesh - 15,606 nodes and 45,878 edges) @http://www.cse...vn/hoai/download/parallelcomputing/2011-2012
4elt.graph: undirected graph, unweighted We assume that weight of edges are 1
Graph algorithms
Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path
Data: 4elt.graph (2D finite element mesh - 15,606 nodes and 45,878 edges) @http://www.cse...vn/hoai/download/parallelcomputing/2011-2012
4elt.graph: undirected graph, unweighted We assume that weight of edges are 1
Graph algorithms