Graph Algorithms (Chapter 10) - Aalborg...
Transcript of Graph Algorithms (Chapter 10) - Aalborg...
![Page 1: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/1.jpg)
1
Graph Algorithms(Chapter 10)
Alexandre DavidB2-206
![Page 2: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/2.jpg)
2
27-04-2007 Alexandre David, MVP'07 2
TodayRecall on graphs.Minimum spanning tree (Prim’s algorithm).Single-source shortest paths (Dijkstra’salgorithm).All-pair shortest paths (Floyd’s algorithm).Connected components.
![Page 3: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/3.jpg)
3
27-04-2007 Alexandre David, MVP'07 3
Graphs – DefinitionA graph is a pair (V,E )
V finite set of vertices.E finite set of edges.e ∈ E is a pair (u,v ) of vertices.Ordered pair → directed graph.Unordered pair → undirected graph.
![Page 4: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/4.jpg)
4
27-04-2007 Alexandre David, MVP'07 4
edge
vertex
V=E=
V=E=
![Page 5: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/5.jpg)
5
27-04-2007 Alexandre David, MVP'07 5
Graphs – EdgesDirected graph:
(u,v ) ∈ E is incident from u and incident to v.(u,v ) ∈ E : vertex v is adjacent to u.
Undirected graph:(u,v ) ∈ E is incident on u and v.(u,v ) ∈ E : vertices u and v are adjacent to each other.
![Page 6: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/6.jpg)
6
27-04-2007 Alexandre David, MVP'07 6
4 adjacent to 6
![Page 7: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/7.jpg)
7
27-04-2007 Alexandre David, MVP'07 7
Graphs – PathsA path is a sequence of adjacent vertices.
Length of a path = number of edges.Path from v to u ⇒ u is reachable from v.Simple path: All vertices are distinct.A path is a cycle if its starting and ending vertices are the same.Simple cycle: All intermediate vertices are distinct.
![Page 8: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/8.jpg)
8
27-04-2007 Alexandre David, MVP'07 8
Simple path:Simple cycle:Non simple cycle:
Simple path:Simple cycle:Non simple cycle:
![Page 9: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/9.jpg)
9
27-04-2007 Alexandre David, MVP'07 9
GraphsConnected graph: ∃ path between any pair.G’=(V’,E’) sub-graph of G=(V,E) if V’⊆V and E’⊆E.Sub-graph of G induced by V’: Take all edges of E connecting vertices of V’⊆V.Complete graph: Each pair of vertices adjacent.Tree: connected acyclic graph.
![Page 10: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/10.jpg)
10
27-04-2007 Alexandre David, MVP'07 10
Sub-graph:Induced sub-graph:
![Page 11: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/11.jpg)
11
27-04-2007 Alexandre David, MVP'07 11
Graph RepresentationSparse graph (|E| much smaller than |V|2):
Adjacency list representation.
Dense graph:Adjacency matrix.
For weighted graphs (V,E,w): weighted adjacency list/matrix.
![Page 12: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/12.jpg)
12
27-04-2007 Alexandre David, MVP'07 12
⎩⎨⎧ ∈
=otherwise
Evvifa ji
ji 0
),(1,
Undirected graph ⇒ symmetric adjacency matrix.
|V|
|V|2 entries
![Page 13: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/13.jpg)
13
27-04-2007 Alexandre David, MVP'07 13
|V|
|V|+|E| entries
![Page 14: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/14.jpg)
14
27-04-2007 Alexandre David, MVP'07 14
Minimum Spanning TreeWe consider undirected graphs.Spanning tree of (V,E) = sub-graph
being a tree andcontaining all vertices V.
Minimum spanning tree of (V,E,w) = spanning tree with minimum weight.Example: minimum length of cable to connect a set of computers.
![Page 15: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/15.jpg)
15
27-04-2007 Alexandre David, MVP'07 15
Spanning Trees
![Page 16: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/16.jpg)
16
27-04-2007 Alexandre David, MVP'07 16
Prim’s AlgorithmGreedy algorithm:
Select a vertex.Choose a new vertex and edge guaranteed to be in a spanning tree of minimum cost.Continue until all vertices are selected.
![Page 17: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/17.jpg)
17
27-04-2007 Alexandre David, MVP'07 17
Vertices of minimum spanning tree.
Weights from VT to V.
select
addupdate
![Page 18: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/18.jpg)
18
27-04-2007 Alexandre David, MVP'07 18
![Page 19: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/19.jpg)
19
27-04-2007 Alexandre David, MVP'07 19
![Page 20: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/20.jpg)
20
27-04-2007 Alexandre David, MVP'07 20
![Page 21: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/21.jpg)
21
27-04-2007 Alexandre David, MVP'07 21
Prim’s AlgorithmComplexity Θ(n2).Cost of the minimum spanning tree:
How to parallelize?Iterative algorithm.Any d[v] may change after every loop.But possible to run each iteration in parallel.
∑∈Vv
vd ][
![Page 22: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/22.jpg)
22
27-04-2007 Alexandre David, MVP'07 22
1-D Block Mapping
p processesn verticesn/p vertices per process
![Page 23: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/23.jpg)
23
27-04-2007 Alexandre David, MVP'07 23
Parallel Prim’s Algorithm
1-D block partitioning: Vi per Pi.For each iteration:
Pi computes a local min di[u].All-to-one reduction to P0 to compute the global min.One-to-all broadcast of u.Local updates of d[v].
Every process needs a column of the adjacencymatrix to compute the update.Θ(n2/p) space per process.
![Page 24: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/24.jpg)
24
27-04-2007 Alexandre David, MVP'07 24
AnalysisThe cost to select the minimum entry is O(n/p + log p). The cost of a broadcast is O(log p). The cost of local update of the d vector is O(n/p). The parallel run-time per iteration isO(n/p + log p). The total parallel time (n iterations) is given by O(n2/p + n log p).
![Page 25: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/25.jpg)
25
27-04-2007 Alexandre David, MVP'07 25
AnalysisEfficiency = Speedup/# of processes:E=S/p=1/(1+Θ((p logp)/n).Maximal degree of concurrency = n.To be cost-optimal we can only use up to n/logn processes.Not very scalable.
max at n2/p =Θ(n log p),with bound p=O(n)
Keep cost optimality: p logp=O(n), logp+loglogp=O(logp)=O(logn) →p=O(n/logn).pTP=TS+T0 → T0=O(pn logp)=O((p logp)2).
![Page 26: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/26.jpg)
26
27-04-2007 Alexandre David, MVP'07 26
Single-Source Shortest Paths: Dijkstra’s AlgorithmFor (V,E,w), find the shortest paths from a vertex to all other vertices.
Shortest path=minimum weight path.Algorithm for directed & undirected with non negative weights.
Similar to Prim’s algorithm.Prim: store d[u] minimum cost edge connecting a vertex of VT to u.Dijkstra: store l[u] minimum cost to reach u from s by a path in VT.
![Page 27: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/27.jpg)
27
27-04-2007 Alexandre David, MVP'07 27
Parallel formulation: Same as Prim’s algorithm.
![Page 28: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/28.jpg)
28
27-04-2007 Alexandre David, MVP'07 28
All-Pairs Shortest PathsFor (V,E,w), find the shortest paths between all pairs of vertices.
Dijkstra’s algorithm: Execute the single-source algorithm for n vertices → Θ(n3).Floyd’s algorithm.
![Page 29: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/29.jpg)
29
27-04-2007 Alexandre David, MVP'07 29
All-Pairs Shortest Paths –Dijkstra – Parallel FormulationSource-partitioned formulation: Each process has a set of vertices and compute their shortest paths.
No communication, E=1, but maximal degree of concurrency = n. Poor scalability.
Source-parallel formulation (p>n):Partition the processes (p/n processes/subset), each partition solves one single-source problem (in parallel).In parallel: n single-source problems.
Up to n processes. Solve in Θ(n2 ).
Up to n2 processes, n2/ logn for cost-optimal,in which case solve in Θ(n logn).
![Page 30: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/30.jpg)
30
27-04-2007 Alexandre David, MVP'07 30
Floyd’s AlgorithmFor any pair of vertices vi, vj ∈ V, consider all paths from vi to vj whose intermediate vertices belong to the set {v1,v2,…,vk}.Let pi,j
(k) (of weight di,j(k)) be the minimum-
weight path among them.
1
2
3
5
4
6
7
8
ki
jpi,j
(k)
![Page 31: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/31.jpg)
31
27-04-2007 Alexandre David, MVP'07 31
Floyd’s AlgorithmIf vertex vk is not in the shortest path from vi to vj, then pi,j
(k) = pi,j(k-1).
1
2
3
5
4
6
7
8
ki
j
pi,j(k)
k-1
=pi,j(k-1)
![Page 32: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/32.jpg)
32
27-04-2007 Alexandre David, MVP'07 32
Floyd’s AlgorithmIf vk is in pi,j
(k), then we can break pi,j(k)
into two paths - one from vi to vk and one from vk to vj . Each of these paths uses vertices from {v1,v2,…,vk-1}.
1
2
3
5
4
6
7
8
ki
jpi,j
(k)
di,j(k)=di,k
(k-1)+dk,j(k-1)
![Page 33: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/33.jpg)
33
27-04-2007 Alexandre David, MVP'07 33
Floyd’s AlgorithmRecurrence equation:
Length of shortest path from vi to vj = di,j
(n). Solution set = a matrix.
( ) ⎭⎬⎫
≥=
⎪⎩
⎪⎨⎧
+=
−−− 10
,min
),()1(
,)1(
,)1(
,
)(, kif
kifddd
vvwd
kjk
kki
kji
jikji
![Page 34: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/34.jpg)
34
27-04-2007 Alexandre David, MVP'07 34
Floyd’s Algorithm
Θ(n3)
Also works in place.
How to parallelize?
![Page 35: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/35.jpg)
35
27-04-2007 Alexandre David, MVP'07 35
Parallel Formulation2-D block mapping:
Each of the p processes has a sub-matrix (n/√p)2 and computes its D(k).Processes need access to the corresponding k row and column of D(k-1).kth iteration: Each processes containing part of the kth row sends it to the other processes in the same column. Same for column broadcast on rows.
![Page 36: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/36.jpg)
36
27-04-2007 Alexandre David, MVP'07 36
2-D Mapping
n/√p
![Page 37: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/37.jpg)
37
27-04-2007 Alexandre David, MVP'07 37
Communication
![Page 38: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/38.jpg)
38
27-04-2007 Alexandre David, MVP'07 38
Parallel Algorithm
![Page 39: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/39.jpg)
39
27-04-2007 Alexandre David, MVP'07 39
Analysis
E=1/(1+Θ((√p logp)/n).Cost optimal if up to O((n/ logn)2) processes.Possible to improve: pipelined 2-D block mapping: No broadcast, send to neighbour. Communication: Θ(n), up to O(n2) processes & cost optimal.
![Page 40: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/40.jpg)
40
27-04-2007 Alexandre David, MVP'07 40
All-Pairs Shortest Paths: Matrix Multiplication Based AlgorithmMultiplication of the weighted adjacency matrix with itself – except that we replace multiplications by additions, and additions by minimizations.The result is a matrix that contains shortest paths of length 2 between any pair of nodes. It follows that An contains all shortest paths.
![Page 41: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/41.jpg)
41
27-04-2007 Alexandre David, MVP'07 41
Serial algorithm notoptimal but we canuse n3/logn processesto run in O(log2n).
![Page 42: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/42.jpg)
42
27-04-2007 Alexandre David, MVP'07 42
Transitive ClosureFind out if any two vertices are connected.G*=(V,E*) where E*={(vi,vj)|∃ a path from vi to vj in G}.
![Page 43: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/43.jpg)
43
27-04-2007 Alexandre David, MVP'07 43
Transitive ClosureStart with D=(ai,j or ∞).Apply one all-pairs shortest paths algorithm.Solution:
⎪⎩
⎪⎨⎧
=>
∞=∞=
jiordif
difa
ji
jiji 01 ,
,*,
Also possible to modify Floyd’s algorithm by replacing + by logical or and min by logical and.
![Page 44: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/44.jpg)
44
27-04-2007 Alexandre David, MVP'07 44
Connected ComponentsConnected components of G=(V,E) are the
maximal disjoint sets C1,…,Ck s.t. V=UCkand u,v ∈ Ci iff u reachable from v and v reachable from u.
![Page 45: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/45.jpg)
45
27-04-2007 Alexandre David, MVP'07 45
DFS Based AlgorithmDFS traversal of the graph → forest of (DFS) spanning trees.
![Page 46: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/46.jpg)
46
27-04-2007 Alexandre David, MVP'07 46
![Page 47: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/47.jpg)
47
27-04-2007 Alexandre David, MVP'07 47
Parallel FormulationPartition G into p sub-graphs. Pi has Gi=(V,Ei).
Each Pi computes the spanning forest of Gi.Merge the forests pair-wise.
Each merge possible in Θ(n).Not described in the book – out of scope.Find if an edge of A has its vertices in B:
no for all → union of 2 disjoint sets.yes for one → merge.
![Page 48: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/48.jpg)
48
27-04-2007 Alexandre David, MVP'07 48
Partition the adjacency matrix.1-D partitioning in p stripes of n/pconsecutive rows.
![Page 49: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/49.jpg)
49
27-04-2007 Alexandre David, MVP'07 49
P1
P2
![Page 50: Graph Algorithms (Chapter 10) - Aalborg Universitetpeople.cs.aau.dk/~adavid/teaching/MTP-07/15-MVP07.pdf · 2 27-04-2007 Alexandre David, MVP'07 2 Today Recall on graphs. Minimum](https://reader033.fdocuments.net/reader033/viewer/2022042911/5f42210d0300b86f963dabb9/html5/thumbnails/50.jpg)
50
27-04-2007 Alexandre David, MVP'07 50
Analysis
E=1/(1+Θ((p logp)/n).Up to O(n/ logn) to be cost-optimal.Performance similar to Prim’s algorithm.