0% found this document useful (0 votes)
55 views

Talk Graph Algorithms

This document discusses graph theory and algorithms. It begins with definitions of graph representations including adjacency matrix and adjacency list. It then covers basic graph problems like minimum spanning tree, single-source shortest path, and all-pairs shortest path. Algorithms for solving these problems are presented, including Prim's algorithm, Dijkstra's algorithm, and Floyd-Warshall algorithm. The document concludes with discussing parallelization approaches and an assignment on parallel shortest path algorithms.

Uploaded by

Dinh Nguyen Cat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Talk Graph Algorithms

This document discusses graph theory and algorithms. It begins with definitions of graph representations including adjacency matrix and adjacency list. It then covers basic graph problems like minimum spanning tree, single-source shortest path, and all-pairs shortest path. Algorithms for solving these problems are presented, including Prim's algorithm, Dijkstra's algorithm, and Floyd-Warshall algorithm. The document concludes with discussing parallelization approaches and an assignment on parallel shortest path algorithms.

Uploaded by

Dinh Nguyen Cat
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

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

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Definitions & representation


Study Advanced Algorithms

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Definitions & representation


Study Advanced Algorithms Representation
Adjacency-matrix A: (normally) for dense graph Incident-matrix B: with size |V | |E | 1 if edge e leaves vertex i 1 if edge e enters vertex i bie = 0 otherwise Adjacency-list representation: (normally) for sparse graph

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Definitions & representation


Study Advanced Algorithms Representation
Adjacency-matrix A: (normally) for dense graph Incident-matrix B: with size |V | |E | 1 if edge e leaves vertex i 1 if edge e enters vertex i bie = 0 otherwise Adjacency-list representation: (normally) for sparse graph

Weighted graph G = (V , E ) aij = wij if (i, j) E 0 otherwise


Graph algorithms

Tran, Van Hoai

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Notations

I (v ), I + (v ), I (v ) E : incident, incident-out, incident-in edge set of v A(v ) V : adjacent vertex set of v

Tran, Van Hoai

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

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Minimum spanning tree


IP model
min s.t.
eE

= |V | 1 x(u,v ) |S| 1 S V (u,v )E :uS,v S xe {0, 1} e E

we xe eE xe

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Minimum spanning tree


IP model
min s.t.
eE

= |V | 1 x(u,v ) |S| 1 S V (u,v )E :uS,v S xe {0, 1} e E

we xe eE xe

Prims algorithm O(V 2 ) Kruskals algorithm O(|V ||E |)

Tran, Van Hoai

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

Tran, Van Hoai

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

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Parallelization of Prims algorithm


Algorithm 5: Prims algorithm
Input: G , r begin VT = {r }; d[r ] = 0; for v V \ VT do if (r , v ) E then d[v ] = w(r ,v ) ; else d[v ] = ; end while VT = V do u = arg minv V \V {d[v ]}; T VT = VT {u}; for v V \ VT do d[v ] = min{d[v ], w(u,v ) }; end end end

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Parallelization of Prims algorithm


Parallelization

Algorithm 6: Prims algorithm


Input: G , r begin VT = {r }; d[r ] = 0; for v V \ VT do if (r , v ) E then d[v ] = w(r ,v ) ; else d[v ] = ; end while VT = V do u = arg minv V \V {d[v ]}; T VT = VT {u}; for v V \ VT do d[v ] = min{d[v ], w(u,v ) }; end end end

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Parallelization of Prims algorithm


Parallelization

Algorithm 7: Prims algorithm


Input: G , r begin VT = {r }; d[r ] = 0; for v V \ VT do if (r , v ) E then d[v ] = w(r ,v ) ; else d[v ] = ; end while VT = V do u = arg minv V \V {d[v ]}; T VT = VT {u}; for v V \ VT do d[v ] = min{d[v ], w(u,v ) }; end end end

Iterative method poor scalability


Tran, Van Hoai Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Single-source shortest path


IP model
min s.t. we xe bse xe eI (v ) bve xe eI (d) bde xe xe {0, 1}
eE eI + (s)

= 1 s is source =0 v V =1 d is destination e E

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Single-source shortest path


IP model
min s.t. we xe bse xe eI (v ) bve xe eI (d) bde xe xe {0, 1}
eE eI + (s)

= 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

All-pairs shortest path


Algorithms for single-source shortest path
Use parallel single-source shortest path algorithm Partition vertices and use sequential single-source shortest path algorithm

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

All-pairs shortest path


Algorithms for single-source shortest path
Use parallel single-source shortest path algorithm Partition vertices and use sequential single-source shortest path algorithm

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

Input: G begin D (0) = A; for k = 1 n do for i = 1 n do for j = 1 n do dij


(k)

=
(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

Parallelization of Floyd-Warshall (1)

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Parallelization of Floyd-Warshall (2)

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Maximum flow problem


IP model max s.t.
eI + (s) xe

xe Z +

eI (v )

bve xe = 0 v V \ {s, d} e E

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Maximum flow problem


IP model max s.t.
eI + (s) xe

xe Z +

eI (v )

bve xe = 0 v V \ {s, d} e E

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Maximal independent set


I V is called independent iff u, v I , (u, v ) E

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Maximal independent set


I V is called independent iff u, v I , (u, v ) E
{a, d, i, h} is an independent set {a, c, j, f , g } is a maximum independent set {a, d, h, f } is a maximal independent set

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Maximal independent set


I V is called independent iff u, v I , (u, v ) E
{a, d, i, h} is an independent set {a, c, j, f , g } is a maximum independent set {a, d, h, f } is a maximal independent set

IP model
max s.t.
v V xv xv + uA(v ) auv xu xv {0, 1}

= 1 v V v V

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Rubys randomized algorithm

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Other aspects of shortest path problem


Johnsons algorithm: use priority queue to store labels for v V \ VT

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Other aspects of shortest path problem


Johnsons algorithm: use priority queue to store labels for v V \ VT Geometric shortest path
Geometric objects implicitly encoding graph and its weights Shortest path in simple polygon

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Assignment 2 - Parallel 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)

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Assignment 2 - requirements (1)

C/C++ source code Short presentation (15 minutes): PowerPoint file


Vietnamese, font size 11 Contents: (i) (algorithmic) idea, (ii) computational experiments (1 4 processes) (parameter consideration) , (iii) remarks

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Assignment 2 - requirements (2)

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

Tran, Van Hoai

Graph algorithms

Basic graph theory Graph problems and algorithms Sparse graphs Assignment 2 - Shortest path

Assignment 2 - requirements (2)

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

Due date: 18 Dec, 2011

Tran, Van Hoai

Graph algorithms

You might also like