Parallel Programming – Graph Algorithms David Monismith CS599 Notes are primarily based upon Introduction to Parallel Programming, Second Edition by Grama,

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar
Graph Algorithms Carl Tropper Department of Computer Science McGill University.
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 12 Graphs.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
Graph II MST, Shortest Path. Graph Terminology Node (vertex) Edge (arc) Directed graph, undirected graph Degree, in-degree, out-degree Subgraph Simple.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Graph Algorithms. Definitions and Representation An undirected graph G is a pair (V,E), where V is a finite set of points called vertices and E is a finite.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar Adapted for 3030 To accompany the text ``Introduction to Parallel Computing'',
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Parallel Programming: All-Pairs Shortest Path CS599 David Monismith Based upon notes from multiple sources.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
Minimum Spanning Trees CS 146 Prof. Sin-Min Lee Regina Wang.
Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text ``Introduction to Parallel Computing'', Addison Wesley,
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Graph Algorithms Gayathri R To accompany the text ``Introduction to Parallel Computing'', Addison Wesley, 2003.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Graphs Upon completion you will be able to:
Graph Theory. undirected graph node: a, b, c, d, e, f edge: (a, b), (a, c), (b, c), (b, e), (c, d), (c, f), (d, e), (d, f), (e, f) subgraph.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Data Structures and Algorithm Analysis Graph Algorithms Lecturer: Jing Liu Homepage:
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Graphs David Kauchak cs302 Spring Admin HW 12 and 13 (and likely 14) You can submit revised solutions to any problem you missed Also submit your.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
Lecture 20. Graphs and network models 1. Recap Binary search tree is a special binary tree which is designed to make the search of elements or keys in.
Minimum Spanning Trees
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Parallel Graph Algorithms
Short paths and spanning trees
Autumn 2016 Lecture 11 Minimum Spanning Trees (Part II)
Graph Algorithm.
Minimum Spanning Trees
Modeling and Simulation NETW 707
Graphs Chapter 13.
Autumn 2015 Lecture 11 Minimum Spanning Trees (Part II)
Graphs.
Chapter 11 Graphs.
CS 584 Project Write up Poster session for final Due on day of final
Graphs G = (V, E) V are the vertices; E are the edges.
CSE 417: Algorithms and Computational Complexity
Parallel Graph Algorithms
Spanning Trees Lecture 20 CS2110 – Spring 2015.
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
More Graphs Lecture 19 CS2110 – Fall 2009.
Presentation transcript:

Parallel Programming – Graph Algorithms David Monismith CS599 Notes are primarily based upon Introduction to Parallel Programming, Second Edition by Grama, Gupta, Karypis, and Kumar

Graphs – Directed vs. Undirected Undirected graph – pair of edges and vertices (V, E). – V is a finite set of points, representing vertices. – E is a finite set of unordered pairs of points, representing edges. Directed graph – also a pair of edges and vertices (V, E). – Edges are ordered pairs

Graphs – Adjacency and Paths We will primarily deal with undirected graphs in this class. Adjacency exists between a pair of points u and v in an undirected graph if an edge exists between u and v. A path from vertex v to vertex u exists if there exists a set of edges that connect vertex v to vertex u. The path length is defined as the number of edges in the path. Provided all vertices in the path are distinct, the path is called “simple”.

Graphs – Cyclic vs. Acyclic A path is called a cycle if the starting and ending points are the same. A graph with no cycles is called an acyclic graph. – Trees are an example of a connected acyclic graph. An undirected graph where every pair of vertices is connected by a path is called connected. A complete graph is a graph wherein every pair of vertices is adjacent. Within a tree, |E| = |V| - 1. Note that the pipes indicate cardinality in this context.

Representing Graphs on Computers Two general methods exist to represent graphs on computers. – Adjacency matrix – Adjacency list An adjacency matrix is an N*N matrix wherein each element of the matrix represents an edge within a graph. – The existence of an edge is represented by a 1 – Non-existence is represented by a zero. – An example of an adjacency graph will be drawn in class.

Representing Graphs on Computers The adjacency matrix can be modified to include weights as follows: – A i,j = 0, if i == j – A i,j = w i,j, if an edge exists between vertices i and j – A i,j = ∞, if no edge exists between vertices i and j Similarly, an adjacency list can be created by storing only the values for which edges exist.

Adjacency List vs. Matrix Generally, the choice to use a list over a matrix is based upon a single factor. – Are the edges sparse or dense? If edges are sparse, a list has a lower space complexity. If edges are dense, it will be faster to use a matrix. Sparseness can be determined by comparing |E| to |V| 2. If |E| << |V| 2, then the edges are sparse.

Goals Find the shortest path through a graph Find the shortest path using a parallel algorithm Determine which parallel algorithms are efficient and have high performance (under certain circumstances).

Minimum Spanning Tree (MST) Spanning tree – undirected graph containing all vertices of a graph G, and is a subgraph of G. Minimum Spanning Tree (MST) – a spanning tree for a weighted undirected graph with minimum weight. Example: find the shortest path between Maryville, MO and Benbrook, TX

Prim’s Algorithm – Finding the MST Greedy Algorithm First, select an arbitrary vertex. Grow the MST by selecting a new vertex and edge guaranteed to be in a MST. Repeat until all vertices have been selected.

Prim’s Algorithm MST(V, E, weight, root) Vtemp = {root}; d[root] = 0; for each vertex v not in Vtemp if an edge exists between v and root, d[v] = weight(root, v); else d[v] = ∞; endif endfor while Vtemp does not contain all vertices, select vertex u where d[u] is the minimum weight for all vertices not in Vtemp; Add u to Vtemp; for each vertex not in Vtemp, d[v] = min(d[v], weight(u,v)); endfor endwhile

Parallelization It is not straightforward to partition the while loop in Prim’s algorithm. Given p processes and n vertices, give each process n/p vertices. Let V i be the vertices for process P i. – Each P i stores the part of array d for V i. – P i computes d i [u] as the minimum weight for all vertices in V i that are not yet in V temp. – A global minimum is computed using an all-to-one reduction over d i [u] into P 0. – P 0 broadcasts u to all processes. – u is added to V temp.

Complexity of Prim’s Algorithm The serial version of Prim’s Algorithm is O(n 2 ). Determining the work and step complexity of the parallelized version is not straightforward. – Over each iteration the computations performed are O(n/p) by each process. – The communications performed by each process over each iteration are O(log p) – This does result in a work efficient algorithm, however, the cost of communication is somewhat high, therefore it is recommended that Prim’s Algorithm use at most O(n/lg n) processes

Dijkstra’s Algorithm Dijkstra’s algorithm is a single source, shortest path algorithm. It finds the shortest paths from one vertex to all other vertices in a graph. A shortest path is defined as a minimum weight path. Edge weights could represent distance, cost, penalty, loss, etc.

Dijkstra’s Algorithm This algorithm is very similar to Prim’s Algorithm. Incrementally finds the shortest paths from a source to other vertices in the graph. The algorithm is greedy – it chooses the edge to a vertex that appears closest. Its runtime is O(n 2 )

Dijkstra’s Algorithm DijkstraAlgorithm(V, E, weights, source) Vtemp = {source}; for each vertex v not in Vtemp, if edge(s,v) exists, l[v] = weights(s, v); else l[v] = ∞; endif endfor while Vtemp does not contain all vertices find a vertex u where l[u] is the smallest weight to a vertex not in Vtemp for each vertex v not in Vtemp l[v] = min(l[v], l[u] + weights(u,v)); endfor endwhile

Parallelization Parallelization of Dijkstra’s algorithm is almost identical to that of Prim’s algorithm. Thus, this parallelization results in the same time and space complexity.

All-Pairs Shortest Path Rather than finding the shortest path from one vertex to all other vertices, we may be interested in finding the shortest paths between all pairs of vertices. Next time we will investigate Floyd’s Algorithm, which is one method for finding an all-pairs shortest path. Thereafter, we will investigate depth-first search.