Parallel Pointers: Graphs

Similar documents
CS140 Final Project. Nathan Crandall, Dane Pitkin, Introduction:

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

Fundamental Algorithms

Recitation 9. Prelim Review

CS61BL. Lecture 5: Graphs Sorting

CSE 613: Parallel Programming. Lecture 11 ( Graph Algorithms: Connected Components )

CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs

CS/COE

CS521 \ Notes for the Final Exam

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design and Analysis

Trees. Arash Rafiey. 20 October, 2015

Graphs. The ultimate data structure. graphs 1

Algorithm Design and Analysis

CS301 - Data Structures Glossary By

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10

Outline. Graphs. Divide and Conquer.

INSTITUTE OF AERONAUTICAL ENGINEERING

Parallel Breadth First Search

Algorithm Design and Analysis

Graphs & Digraphs Tuesday, November 06, 2007

22.1 Representations of graphs

UNIT III BALANCED SEARCH TREES AND INDEXING

Depth-First Search Depth-first search (DFS) is another way to traverse the graph.

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

CS 161 Lecture 11 BFS, Dijkstra s algorithm Jessica Su (some parts copied from CLRS) 1 Review

SELF-BALANCING SEARCH TREES. Chapter 11

CSE 100 Minimum Spanning Trees Prim s and Kruskal

CSE 100: GRAPH ALGORITHMS

12 Abstract Data Types

Computer Science 136 Spring 2004 Professor Bruce. Final Examination May 19, 2004

Lecture Summary CSC 263H. August 5, 2016

CS4800: Algorithms & Data Jonathan Ullman

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Graphs. The ultimate data structure. graphs 1

CS106X Final Review. Rachel Gardner and Jared Bitz. slides adapted from Ashley Taylor, Anton Apostolatos, Nolan Handali, and Zachary Birnholz

Balanced Trees Part Two

Announcements Problem Set 4 is out!

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

CMSC132, Practice Questions

Data Structures Question Bank Multiple Choice

Data Structure. IBPS SO (IT- Officer) Exam 2017

Algorithms and Theory of Computation. Lecture 3: Graph Algorithms

Introduction to Computer Science

FINAL EXAM REVIEW CS 200 RECITATIOIN 14

Questions from the material presented in this lecture

Topic 18 Binary Trees "A tree may grow a thousand feet tall, but its leaves will return to its roots." -Chinese Proverb

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

MLR Institute of Technology

CS350: Data Structures B-Trees

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

Lecture 25 Spanning Trees

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Algorithms: Lecture 10. Chalmers University of Technology

V Advanced Data Structures

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Lecture 17: Breadth-First Search (BFS) built on 2017/06/16 at 11:05:40

Searching in Graphs (cut points)

Parallel and Sequential Data Structures and Algorithms Lecture (Spring 2012) Lecture 16 Treaps; Augmented BSTs

W4231: Analysis of Algorithms

March 20/2003 Jayakanth Srinivasan,

Algorithms Activity 6: Applications of BFS

Graphs Introduction and Depth first algorithm

DS ata Structures Aptitude

1. O(log n), because at worst you will only need to downheap the height of the heap.

Outlines: Graphs Part-2

Math 15 - Spring Homework 5.2 Solutions

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Distributed Algorithms 6.046J, Spring, Nancy Lynch

Graph Algorithms using Map-Reduce. Graphs are ubiquitous in modern society. Some examples: The hyperlink structure of the web

CISC 320 Midterm Exam

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Solutions to Exam Data structures (X and NV)

Algorithms (VII) Yijia Chen Shanghai Jiaotong University

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Final Examination CSE 100 UCSD (Practice)

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Multiple-choice (35 pt.)

GIAN Course on Distributed Network Algorithms. Spanning Tree Constructions

Undirected Graphs. Hwansoo Han

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.


CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

V Advanced Data Structures

Friday Four Square! 4:15PM, Outside Gates

Lecture 4: Graph Algorithms

( D. Θ n. ( ) f n ( ) D. Ο%

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

CSI 604 Elementary Graph Algorithms

Introduction to Linked List: Review. Source:

3.1 Basic Definitions and Applications

CSE 530A. B+ Trees. Washington University Fall 2013

LECTURE 11 TREE TRAVERSALS

Lecture 25 Notes Spanning Trees

Warm Up. Use Kruskal s algorithm to find the minimum spanning tree and it s weight.

Transcription:

Parallel Pointers: Graphs Breadth first Search (BFS) 101 Given a vertex S, what is the distance of all the other vertices from S? Why would this be useful? To find the fastest route through a network. To do a BFS keep a distance for each vertex. 1. S is the first vertex it is 0 distance from itself. Set all the other vertices to infinity. 2. Begin at S. Look at its immediate neighbors. Their distance for S is 1. 3. Now move to these immediate neighbors and mark the distance between these neighbors as one. 4. Do this for each vertex in the graph. Each successive advancement vertices being examined is called a Frontier. Start with a graph G. Set all the distances to infinity Set the source distance to 0 Determine the frontier F of S Look at each vertex in the frontier Examine each neighbor w of each vertex If the distance of that neighbor is infinity, it has not been visited. If it has not been visited the neighbors distance is the vertex s distance + 1 Do this for all vertices in the search. What does this algorithm cost? By cost we mean running time. 1. The frontier only grows when an unvisited vertices is inserted. Which means the frontier can only be as large as the number of vertices. 2. Each edge is visited at most once, if the graph is directed.

3. If the graph is undirected, each edge will be visited at most twice. This means the runtime is linear and the size of the graph BFS Quiz Note this is a directed graph. When looking for neighbors of S look only at those vertices that go INTO S, not out of it. For example, d is a neighbor of S and f is NOT. Analysis Is BFS Inherently Sequential? Can this algorithm be parallelized? There is a bottleneck in the relationship between extracting v, inserting w. The available parallelism is W/D which is dependent upon E / V. Is this a good thing or not? In real life, graphs are sparse. So E = O( V ). This means the average available parallelism will be a constant and that is bad. This leads to the conclusion that the sequential algorithm is bad. Intuition Why we might do better The BFS visits the graph in waves. There are two important implications from this fact: 1. The upper bound on the span should be the number of waves, not the number of vertices. These waves are called levels. A level is all of the vertices equidistant to the source. The diameter of a graph is the maximum shortest distance between any pair of vertices. Diameter is a property of the whole graph, and is an upper bound on the number of levels of any starting vertex. Level synchronous transversal is visiting the nodes level by level. 2. If you perform a level synchronous BFS, then the order in which you visit each vertex of a given frontier is immaterial. This means we can visit them at the same time.

So this is an opportunity for parallelism all the vertices of a frontier can be visited at the same time. High Level Approach to Parallel BFS 1. Carry out the BFS level by level (not vertex by vertex) 2. Process the entire level in parallel we can do this because the order in which the vertices are visited should not matter. This is very similar to the serial version, with a few exceptions. l 0.. the code is level synchronous. This is the level counter set to 0 The frontiers referenced are also level specific (F l ) l l + 1. increments the counter The span (defined by the while loop) will be no larger than the diameter of the graph distances (D) Process level will: take the graph and the current frontier. It will produce a new frontier and update the Bag: Key Properties The data structure to be used with the parallel BFS is a bag. A bag has the following data properties: The data is an unordered collection It will allow repetition Allow redundant insertions of the same vertex, if necessary A bag has the following operational properties: Fast traversal Fast and logically associative union and split Logically associative means if A U B == B U A This will also give the ability to apply Reducer Hyper Objects. Pennant, Building Blocks for Bags

Pennant is: a tree with 2 k nodes and a unary root having a child. the child is the root of a complete binary tree. X is the root X s is the complete binary tree If there are two pennants, and they are EXACTLY THE SAME SIZE ( X == Y ) Then the two pennants can be combined. 1. Choose one of the roots to be the root of the combined pennant. 2. The two pennants are now children of the root. The combination is also a pennant. There will now be 2 k + 1 nodes. This was fairly easy, it involved rearranging pointers. The reverse, splitting a pennant into two pennants can be done using the reverse of the given method.

Combining Pennants into Bags Pennants are good for representing collections that have a size 2 N, but there needs to be something for other size collections. A bag needs to contain any size collection. How can pennants be used to form bags? An example of pennants used to put a collection in a bag. 23 items. Divided into groups of powers of 2. (23 = 10111) To connect these groups, use an array of pointers, use the null pointer for any empty bits. This array is called a spine. To insert a new element into the collection. 1. Try to insert it into the LSB 2. If the LSB is occupied, combine the LSB with the new element and carry it. 3. Move to the next LSB, repeat the process. What is the Cost of Insertion? Remember when inserting an element, you may need to traverse the entire spine. An integer of size N needs N bits to store its power. Inserting an element is simply a matter of shuffling pointers. It takes the same asymptotic time to insert N elements into a bag as it does to insert 1. The amortized time to insert elements into a bag is constant.

Bag Splitting A right bit shift is the same a division by two. To split a bag an empty bag is also necessary. Split the pennant in half. Store 1 of the halves in the spare bag and one in the next lower bit on the bag. The cost of splitting a bag.. Finishing the Parallel BFS with Bags If the bag is big enough use divide and conquer otherwise use the sequential method. The difference with this sequential method is the for loop this uses a parallel for loop. There is a data race here as each task tries to update the neighbors. This is perfectly safe here. The costs are tricky for this experiment. Span is affected by the number of levels. Span of process level has 3 parts: depth, cost of splitting, cost of the base case.