Parallel Graph Algorithms: Traversing, Connected Components, and Shortest Paths - Prof. Ji, Study notes of Computer Science

This document from portland state university covers parallel strategies for traversing graphs, finding connected components using hirshberg's algorithm, and solving single-source shortest paths problems using moore's algorithm. The document also discusses the parallelization of these algorithms.

Typology: Study notes

Pre 2010

Uploaded on 08/16/2009

koofers-user-mdp
koofers-user-mdp 🇺🇸

10 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Graph Algorithms
Jingke Li
Portland State University
Jingke Li (Portland State University) CS 415/515 Graph Algorithms 1 / 25
Graph Algorithms
Graph algorithms are frequently used in non-numerical applications. We’d
like to examine parallel algorithms for a few common graph problems.
Graph Basics:
Jingke Li (Portland State University) CS 415/515 Graph Algorithms 2 / 25
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Parallel Graph Algorithms: Traversing, Connected Components, and Shortest Paths - Prof. Ji and more Study notes Computer Science in PDF only on Docsity!

Graph Algorithms

Jingke Li

Portland State University

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 1 / 25

Graph Algorithms

Graph algorithms are frequently used in non-numerical applications. We’d like to examine parallel algorithms for a few common graph problems.

Graph Basics:

Problem 1. Traversing a Graph

Common strategies include

  • Depth-First Search

6 5

7

1

4

2 3

9 8

6 5

7

1

4

2 3

9 8

(1) (2)

(3)

(4)

1

2 3 4

7 8

6 9

5

(1) (9) (10)

(2) (8)

(3) (6)

(4)

(7)

(5)

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 3 / 25

Traversing a Graph (cont.)

  • Breadth-First Search

6 5

7

1

4

2 3

9 8

6 5

7

1

4

2 3

9 8

(1) (2)

(4) (3)

1

2 3 4 5

7 8 9 6

(1) (2) (3) (4)

(5) (6) (7) (8)

(9) (^) (10)

Parallel Traversal Strategies (cont.)

Traversing a graph with p processors.

  • (^) Breadth-First Search — Processors examine all edges at a certain level of the search tree before continuing to the next level.

6 5

7

1

4

2 3

9 8

6 5

7

1

4

2 3

9 8

(1) (1)

(2) (2)

(3) (4) (3)

(4) (5)

(5)

1

2 3 4 5

7 8 9 6

(1) (1) (2) (2)

(3) (3) (4) (4)

(5) (^) (5)

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 7 / 25

Problem 2. Connected Components

1 8

4 6

3 2

5 7

Common Approaches:

  1. Use some form of search, e.g. depth-first or breadth-first.
  2. Find the transitive closure of the graph’s adjacency matrix.
  3. Collapse nodes into sets of nodes (“components”); continually collapse them into larger and larger sets until each set corresponds to a single connected component of the graph.

Hirshberg’s Parallel Algorithm

Based on the 3rd approach.

  • (^) Each node is always a member of exactly one super-node.
  • (^) Every super-node is identified by its lowest-numbered member node, the root.

It iterates over three stages:

  1. The lowest-numbered neighboring super-node of each node is found;
  2. Connect each super-node root to the root of the lowest-numbered neighboring super-node;
  3. All newly-connected super-nodes are collapsed into larger super-nodes.

Complexity: O(log^2 n) with n^2 processors.

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 9 / 25

Hirshberg’s Algorithm Example

1 8

4 6

3 2

5 7

node 1 2 3 4 5 6 7 8 root 1 2 3 4 5 6 7 8

Iteration 1:

  • Find lowest neighboring super-node.

1 8

4 6

3 2

5 7

node 1 2 3 4 5 6 7 8 min nbr rt 8 6 3 6 7 2 2 1

Example (cont.)

  • Connect super-node roots.

1 8

4 6

3 2

5 7

4 6

3 2

5 7

  • Build new super-nodes (through pointer-jumping).

1 8

4 6

3 2

5 7

node 1 2 3 4 5 6 7 8 root 1 1 3 1 1 1 1 1

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 13 / 25

Pseudo Code for Hirshberg’s Algorithm

forall (i in V) R(i) = i for (t = 0; t < log n; t++) { forall (i in V) { T(i) = min_j { R(j) | A(i,j)=1 && R(j) != R(i) } if none then R(i) } forall (i in V) { T(i) = min_j { T(j) | R(j)=i, T(j) != i } if none then R(i) } forall (i in V) R(i) = T(i) for (k = 0; k < log n; k++) { forall (i in V) T(i) = T(T(i)) } forall (i in V) R(i) = min { R(T(i)), T(i) } }

Problem 3. All-Pairs Shortest Path

Given an n-node weighted graph G , the goal is to produce an n × n matrix A, where aij is the length of the shortest path from node i to node j.

Matrix-Multiplication Based Algorithm:

  • (^) Consider a matrix, A^1 , where a^1 ii = 0 and a^1 ij is the weight of the edge from i to j (infinity if no edge exits).
  • Perform “plus-min” multiplications on A^1 :

A = An−^1 = A^1 ◦ A^1 ◦ · · · ◦ A^1

With optimization, the number of matrix multiplications can be reduced to O(log n).

Complexity: O(log^2 n) with O(n^3 ) processors.

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 15 / 25

Problem 4. Single-Source Shortest Path

The problem is to find the shortest path from a specified node, s, to all other nodes in a weighted directed graph.

Moore’s Algorithm:

  • distance(v ) is initially assigned the value ∞, for all v ∈ V − {s}.
  • A queue contains nodes from which further searching must be done; initially it contains s.
  • Repeat the following step until the queue is empty:
    • Remove a node u from the queue, and examine all edges (u, v ) ∈ E.
    • (^) If distance(u) + weight(u, v ) < distance(v ), update distance(v ) with the new value.
    • (^) Add v to the queue.

Problem 5. Minimum Spanning Tree

Find the min-cost spanning tree for a weighted, undirected, connected graph.

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 19 / 25

Prim’s Greedy Algorithm

Start the tree with any node, then repeat the following step until all nodes are on the tree: Find the edge of lowest weight that connects a node already on the tree to a node not on the tree; then add the edge and the node to the tree.

Complexity: O(n^2 )

Parallelizing Prim’s Algorithm

The step of finding the edge of lowest weight can be parallelized:

Parallel Complexity: Θ(

n^2 p

) + Θ(n log p)

Jingke Li (Portland State University) CS 415/515 Graph Algorithms 21 / 25

Sollin’s Algorithm

Start with a forest of n trees (each containing a single node); then iterate the following step until there is only one tree remaining:

  • For each tree, find the shortest edge joining that tree with another tree; add all such edges to the forest (reducing the number of trees), except that two trees are never joined by more than one edge.

A

B C

D

G F E

H

I

4 3 1

6

5 5 2 1

7

2 4

3

1

A

B C

D

G F E

H

I

4 3 1

6

5 5 2 1

7

2 4

3

1

The algorithm’s complexity is O(n^2 log n).

Comments: Can be parallelized with domain decomposition.

Parallelizing Kruskal’s Algorithm

A

B

C D E

7 5 3

8 9 1 6

  1. Construct a heap out of the edges of the weight graph, based on their lengths. (Cost: O(E ))
  2. A single process removes an edge from the heap and determines whether it is an element of the minimum spanning tree, while the remaining processes repeatedly restore the heap. (Cost: O(1) with log E processors)
  3. Repeat Step 2 until the heap is empty.