PRAM Divide and Conquer Algorithms

Similar documents
Divide and Conquer Algorithms

Parallel Algorithms for (PRAM) Computers & Some Parallel Algorithms. Reference : Horowitz, Sahni and Rajasekaran, Computer Algorithms

CS473 - Algorithms I

The divide and conquer strategy has three basic parts. For a given problem of size n,

Chapter 3: The Efficiency of Algorithms. Invitation to Computer Science, C++ Version, Third Edition

Chapter 3: The Efficiency of Algorithms

Problem. Input: An array A = (A[1],..., A[n]) with length n. Output: a permutation A of A, that is sorted: A [i] A [j] for all. 1 i j n.

Scan and Quicksort. 1 Scan. 1.1 Contraction CSE341T 09/20/2017. Lecture 7

12/30/2013 S. NALINI,AP/CSE

Properties of a heap (represented by an array A)

Lecture 5: Sorting Part A

Jana Kosecka. Linear Time Sorting, Median, Order Statistics. Many slides here are based on E. Demaine, D. Luebke slides

Algorithms. MIS, KUAS, 2007 Ding

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

Scan and its Uses. 1 Scan. 1.1 Contraction CSE341T/CSE549T 09/17/2014. Lecture 8

Hypercubes. (Chapter Nine)

1. (a) O(log n) algorithm for finding the logical AND of n bits with n processors

Chapter 3: The Efficiency of Algorithms Invitation to Computer Science,

Parallel Algorithms. COMP 215 Lecture 22

Data Structures and Algorithms CSE 465

CS221: Algorithms and Data Structures. Sorting Takes Priority. Steve Wolfman (minor tweaks by Alan Hu)

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

We can use a max-heap to sort data.

CS 171: Introduction to Computer Science II. Quicksort

Real parallel computers

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn

EECS 2011M: Fundamentals of Data Structures

Parallel Models RAM. Parallel RAM aka PRAM. Variants of CRCW PRAM. Advanced Algorithms

Parallel Breadth First Search

Lecture 8: Mergesort / Quicksort Steven Skiena

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

Recursion. COMS W1007 Introduction to Computer Science. Christopher Conway 26 June 2003

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

Analyze the obvious algorithm, 5 points Here is the most obvious algorithm for this problem: (LastLargerElement[A[1..n]:

Sorting Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

CS S-11 Sorting in Θ(nlgn) 1. Base Case: A list of length 1 or length 0 is already sorted. Recursive Case:

SORTING AND SELECTION

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn

CS2 Algorithms and Data Structures Note 6

Data Structures and Algorithms Running time, Divide and Conquer January 25, 2018

CSE 373: Data Structures and Algorithms

Algorithms and Data Structures (INF1) Lecture 7/15 Hua Lu

COMP Parallel Computing. PRAM (2) PRAM algorithm design techniques

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

II (Sorting and) Order Statistics

Cilk, Matrix Multiplication, and Sorting

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1

Parallel Models. Hypercube Butterfly Fully Connected Other Networks Shared Memory v.s. Distributed Memory SIMD v.s. MIMD

Design and Analysis of Algorithms

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved

CS 303 Design and Analysis of Algorithms

Divide and Conquer Sorting Algorithms and Noncomparison-based

Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment.

Quick Sort. CSE Data Structures May 15, 2002

5. DIVIDE AND CONQUER I

CS2 Algorithms and Data Structures Note 6

Lecture 7 Quicksort : Principles of Imperative Computation (Spring 2018) Frank Pfenning

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Data Structures and Algorithms Week 4

Lecture 3: Sorting 1

The Limits of Sorting Divide-and-Conquer Comparison Sorts II

Lecture Notes on Quicksort

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

Lecture 2: Divide and Conquer

Lecture Notes on Quicksort

Parallel Algorithms. 6/12/2012 6:42 PM gdeepak.com 1

Minimum Spanning Trees

CS 598: Communication Cost Analysis of Algorithms Lecture 15: Communication-optimal sorting and tree-based algorithms

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Lecture 6 Sequences II. Parallel and Sequential Data Structures and Algorithms, (Fall 2013) Lectured by Danny Sleator 12 September 2013

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS584/684 Algorithm Analysis and Design Spring 2017 Week 3: Multithreaded Algorithms

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.

Sorting is a problem for which we can prove a non-trivial lower bound.

Representations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs

Lecture 3. Recurrences / Heapsort

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

Ch5. Divide-and-Conquer

Sorting. CPSC 259: Data Structures and Algorithms for Electrical Engineers. Hassan Khosravi

Key question: how do we pick a good pivot (and what makes a good pivot in the first place)?

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Merge Sort. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong

Intro to Algorithms. Professor Kevin Gold

1 Computing alignments in only linear space

Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order.

How many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.

COMP Data Structures

Introduction to Algorithms

Computer Science 4U Unit 1. Programming Concepts and Skills Algorithms

FUTURE communication networks are expected to support

CSci 231 Final Review

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Sorting (Chapter 9) Alexandre David B2-206

Solutions to Exam Data structures (X and NV)

Practical Session #11 - Sort properties, QuickSort algorithm, Selection

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

DATA STRUCTURE AND ALGORITHM USING PYTHON

Transcription:

PRAM Divide and Conquer Algorithms (Chapter Five) Introduction: Really three fundamental operations: Divide is the partitioning process Conquer the the process of (eventually) solving the eventual base problems (without dividing). Combine is the process of combining the solutions to the subproblems. Merge Sort Example Divide repeatedly partitions sequence into halves. 1

Conquer sorts the base sets of one element. Combine does most of the work. It repeatedly merges two sorted halves. Quicksort: The divide stage does most of the work. 2

Search Algorithms Usual Format: Have a file of n records. Each record has several data fields and a key field. Problem Statement: Let S s 1, s 2,...,s n be a sorted sequence of integers. Given an integer x, determine if x s k for some k. Possibilities and actions: Case 1. x s k for some k. Action: Return k. Case 2. There is no k with x s k. Action: Return Case 3. There are several successive records, say s k, s k1,...,s ki, whose key field is x. Action: Depends upon the application. Perhaps k is returned. Recall: Sequential Binary Search. Key of middle record in file is compared to x. If equal, procedure stops. Otherwise, top or bottom half of the 3

file is discarded and search continues on other half. Searching using CRCW PRAM with n PEs. One PE, say P 1, reads x and stores it in shared memory All other PEs read x Each processor P i compares x to s i for 1 i n. Those P j (if any) for which x s j use a min-cw to write j into k. Can easily modify for PRIORITY or ARBITRARY, but not COMMON. Searching using PRAM and N PEs with N n. Each P i is assigned the subsequence s i 1 n N 1 x s i n N All PEs read x. Any P i with s i 1 n N 1 x s i n N performs a binary search. All P i with a hit (if any) use MIN-CW 4

to write the index of its hit to k. Problem: Preceding algorithm is slow, as often all PEs but one are idle for most of the algorithm. PRAM BINARY SEARCH Using N processors, we can extend the binary search to become an (N 1)-way search. An increasing sequence is partitioned into N 1 blocks and each PE compares a partition point s with the search value x. If s x, then x can not occur to the right of s, so all elements following S are discarded. If s x, then x can not occur to the left of s, so all elements preceding x are discarded. If s x, then the index of s is returned. Diagram: (Figure 5.3, page 200) 5

drop.. s 1..drop.. s 2..keep.. s 3..drop.. s 4..drop...s ptrs P 1 P 2 P 3 P 4 P If x is not found, the search is narrowed to one block, identified by two successive pointers. This procedure continues recursively. Number of stages required: Let m t be the length of largest block at stage t. The maximum length of blocks in stage 1 is m 1 n N 1 The N 1 blocks of indices at stage 1are 1,..,m 1, m 1 1,..,2m 1,..,N 1m 1 1,..,Nm 1, Nm 1 1,.. We can let P i point to the value i m 1 Clearly Nm 1 n N 1m 1 and m 1 n N since n is in the (N1)th 6

block. Similarly, m 2 m 1 at stage 2, so N m 2 n. N 2 Inductively, m t n. N t Let g be the least integer t with n 1. N t Then, lg n g Θlg lg N N n If n items are divided into N 1 equal parts g successive times, then the maximum length of the remaining segment is 1. Analysis of Algorithm: The time for each stage is a constant. There are at most g iterations of this algorithm so tn Olg N n The sequential binary search algorithm for this problem has a Olg n running time. 7

To show optimality of the running time of this algorithm using this sequential time, we would need to show its running time is O lgn. N Trivial, if N is a constant. Not obvious in general, as N is usually a function of n (e.g., N n ). Instead, here optimality is established by a direct proof in the next lemma. Much better running time than previous naive parallel search algorithm with running time of lg n N lg n lg N Θlg n. Lemma: As defined above, g is a lower bound for the running time of all PRAM comparison-based search algorithms. At the first comparison step, N processors can compare x to at most N elements of S. Note that n N elements are not checked, so one of the N 1 groups created by the 8

partition by these N points has size at least n N/N 1. Moreover, n N N 1 n N N 1 N n 1 1 1 Then the largest unchecked group could hold the key and its size could be at least m N n 1 1 1. Repeating the above procedure again for a setofsizeatleastm could not reduce the size of the maximal unchecked sequence to less than m 1 N 1 1 n 1 N 1 1. 2 After t repetitions of this process, we can not reduce the length of the maximal unchecked sequence to less than n 1 N 1 t 1. Therefore, the number of iterations required by any parallel search algorithm 9

is not less than the minimal value h of t with n 1/N 1 t 1 0 or, equivalently, h is the minimum t such that n 1 N 1 t 1 So at least h iterations will be required by any parallel search algorithm, where lgn 1 h lgn 1 lg 1 0. or lgn 1 h lgn 1. Recall that the running time of PRAM Binary Search is g lg n lg N ASIDE: It is pretty obvious that h g since h partitions into N 1groups each time, while g partitions into N groups each time (as rightmost 10

g group could always have size 1). However, g and h have the same complexity, as g Θ lg n lg N Θ lgn 1 lgn 1 Θh This can be formally by proving that lg n lim n lg N / lgn 1 0 lgn 1 using L Hospital s rule (assuming that N Nn is a differentable function of n). 11