Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 1 An overview of lecture 6 A parallel search algorithm A parallel merging algorithm.

Slides:



Advertisements
Similar presentations
Parallel List Ranking Advanced Algorithms & Data Structures Lecture Theme 17 Prof. Dr. Th. Ottmann Summer Semester 2006.
Advertisements

List Ranking on GPUs Sathish Vadhiyar. List Ranking on GPUs Linked list prefix computations – computations of prefix sum on the elements contained in.
Introduction to Algorithms Quicksort
Back to Sorting – More efficient sorting algorithms.
Introduction to Computer Science Theory
Optimal PRAM algorithms: Efficiency of concurrent writing “Computer science is no more about computers than astronomy is about telescopes.” Edsger Dijkstra.
Advanced Topics in Algorithms and Data Structures Lecture 7.2, page 1 Merging two upper hulls Suppose, UH ( S 2 ) has s points given in an array according.
Lecture 3: Parallel Algorithm Design
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
1 Parallel Parentheses Matching Plus Some Applications.
Partitioning and Divide-and-Conquer Strategies ITCS 4/5145 Parallel Computing, UNC-Charlotte, B. Wilkinson, Jan 23, 2013.
Prune-and-Search Method
CS4413 Divide-and-Conquer
HST 952 Computing for Biomedical Scientists Lecture 9.
CSC 331: Algorithm Analysis Divide-and-Conquer Algorithms.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 5.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
Advanced Topics in Algorithms and Data Structures Lecture pg 1 Recursion.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Advanced Topics in Algorithms and Data Structures Page 1 Parallel merging through partitioning The partitioning strategy consists of: Breaking up the given.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Lecture 3 Nearest Neighbor Algorithms Shang-Hua Teng.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Sorting Algorithms CS 524 – High-Performance Computing.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Advanced Topics in Algorithms and Data Structures 1 Lecture 4 : Accelerated Cascading and Parallel List Ranking We will first discuss a technique called.
1 Lecture 11 Sorting Parallel Computing Fall 2008.
Accelerated Cascading Advanced Algorithms & Data Structures Lecture Theme 16 Prof. Dr. Th. Ottmann Summer Semester 2006.
Lecture 2: Divide and Conquer I: Merge-Sort and Master Theorem Shang-Hua Teng.
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
Fall 2008Array Manipulation Algorithms1. Fall 2008Array Manipulation Algorithms2 Searching Let A = (a 1, a 2, …, a n ) be a sorted array of data such.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Advanced Topics in Algorithms and Data Structures 1 Two parallel list ranking algorithms An O (log n ) time and O ( n log n ) work list ranking algorithm.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
Basic PRAM algorithms Problem 1. Min of n numbers Problem 2. Computing a position of the first one in the sequence of 0’s and 1’s.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
Divide-and-Conquer 7 2  9 4   2   4   7
1 More Sorting radix sort bucket sort in-place sorting how fast can we sort?
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Complexity of algorithms Algorithms can be classified by the amount of time they need to complete compared to their input size. There is a wide variety:
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
1 Designing algorithms There are many ways to design an algorithm. Insertion sort uses an incremental approach: having sorted the sub-array A[1…j - 1],
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
Merge sort, Insertion sort. Sorting I / Slide 2 Sorting * Selection sort (iterative, recursive?) * Bubble sort.
1 Prune-and-Search Method 2012/10/30. A simple example: Binary search sorted sequence : (search 9) step 1  step 2  step 3  Binary search.
Survey of Sorting Ananda Gunawardena. Naïve sorting algorithms Bubble sort: scan for flips, until all are fixed Etc...
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Sorting. Sorting Sorting is important! Things that would be much more difficult without sorting: –finding a telephone number –looking up a word in the.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Concepts of Algorithms CSC-244 Unit 15 & 16 Divide-and-conquer Algorithms ( Binary Search and Merge Sort ) Shahid Iqbal Lone Computer College Qassim University.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
Sorting Quick, Merge & Radix Divide-and-conquer Technique subproblem 2 of size n/2 subproblem 1 of size n/2 a solution to subproblem 1 a solution to.
Unit-8 Sorting Algorithms Prepared By:-H.M.PATEL.
3/12/2013Computer Engg, IIT(BHU)1 PRAM ALGORITHMS-1.
Computer Sciences Department1. Sorting algorithm 4 Computer Sciences Department3.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting Input: sequence of numbers Output: a sorted sequence.
Lecture 3: Parallel Algorithm Design
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Algorithms Part I
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 1 An overview of lecture 6 A parallel search algorithm A parallel merging algorithm A parallel sorting algorithm

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 2 A parallel search algorithm We discuss an algorithm for parallel searching in a sorted array. n is the number of elements in a sorted array S and we use p, p < n processors for searching. The complexity of the parallel searching algorithm is:.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 3 A parallel search algorithm Input: (i)A sorted array S = x 1, x 2,…, x n with n elements. (ii)A query element y. Output: Two elements x i, x i +1 in S such that x i  y  x i +1.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 4 A parallel search algorithm The algorithm consists of a series of iterations to reduce the size of the array where the element y is located. In each iteration, we divide the current array in p + 1 equal parts and locate y in one of the parts. This is continued until the size of the array where y is located is reduced to p. We then do a direct comparison to find two elements x i, x i +1 such that x i  y  x i +1.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 5 A parallel search algorithm

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 6 A parallel search algorithm For each of the p + 1 parts of the array, a processor checks whether y < x l, where x l is the last element of the part. If y x l, the subarray to the left of x l can be rejected. In each iteration we identify only one subarray for further search.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 7 A parallel search algorithm When the size of the remaining array is the same as the number of processors, we do the following. We allocate one processor for each element. The processor assigned to element x i checks whether x i  y  x i +1. Hence it takes O (1) time to locate y once the size of the array has been reduced to p.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 8 Complexity We need to analyze what is the complexity of reducing the size of the array to p. At the first iteration, we are reducing the size of the array from n to n / p. Suppose, the size reduces to p after k iterations. Hence,, which implies n = p k +1.. We need the CREW PRAM model.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 9 Merging We use the parallel search algorithm to design an optimal O (loglog n ) time merging algorithm. rank ( x : X ) is the number of elements of X that are  x. Ranking a sequence Y = ( y 1, y 2, …, y n ) in X is the same as: Computing the integer array : ( r 1, r 2, …, r m ) where r i = rank ( y i, X ).

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 10 Merging If rank ( a i, A ) = r 1 and rank ( a i, B ) = r 2 rank ( a i, A + B ) = r 1 + r 2. Hence, a i should go to the entry number r 1 + r 2 in the merged array.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 11 Ranking a short sequence in a sorted sequence X is a sorted sequence with n elements. Y is an arbitrary sorted sequence of size m such that m = O ( n s ), where s is a constant and 0 < s < 1. If we use processors, Then we can rank each element of Y in X in time.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 12 A fast merging algorithm We now discuss a fast algorithm for merging two sorted arrays A and B with n and m elements each. Fast merging is an essential component in any sorting algorithm based on divide-and-conquer. We will first design an O (loglog m ) time and O (( m + n ) loglog m ) work algorithm. Then we will improve the work to O ( m + n ) which is optimal.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 13 A fast merging algorithm Input: Two sorted sequences A and B of lengths n and m respectively. Output: rank ( B : A ) and rank ( A : B ). We use a strategy similar to the merging algorithm we discussed earlier. We divide the array B into parts, each part with elements. We start with ranking the last element from each part of B into A.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 14 Ranking a sample of elements We start with a sample of elements from B. We choose every –th element from B. These elements can be ranked in A in O (1) time through binary search in parallel using m processors.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 15 A parallel search algorithm

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 16 Ranking elements in O(1) time elements m elementsA B For every element in B, we allocate processors. In one step, we identify the block of elements in A where an element of B will be ranked. We find the rank in another step.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 17 Ranking a sample of elements B is partitioned into blocks, each of size. After the ranking of the elements from B in A. A is also partitioned into blocks. We can now merge the blocks in A and B pairwise recursively.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 18 Independent subproblems Consider the first element of B 2 and the first element of B 3, the elements r and s. Now, r is ranked at u and s is ranked at v. Consider an element p such that r < p < s. p must be ranked in between u and v. Hence, all the elements in B 2 must be ranked in A 2 and vice verse.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 19 Ranking a sample of elements Suppose at the current level of recursion, the size of the two subproblems B’ and A’ are m’ and n’. If m’ > n’, then we divide B’ into parts and apply the algorithm recursively. If n’ > m’, we divide A’ into parts and apply the algorithm recursively.

Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 20 An example