Lecture 7 : Parallel Algorithms (focus on sorting algorithms) Courtesy : SUNY-Stony Brook Prof. Chowdhury’s course note slides are used in this lecture.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Back to Sorting – More efficient sorting algorithms.
Divide and Conquer Yan Gu. What is Divide and Conquer? An effective approach to designing fast algorithms in sequential computation is the method known.
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 6.
Analysis of Algorithms
Practice Quiz Question
Lecture 7-2 : Distributed Algorithms for Sorting Courtesy : Michael J. Quinn, Parallel Programming in C with MPI and OpenMP (chapter 14)
Introduction to Algorithms Jiafen Liu Sept
Divide and Conquer Strategy
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Theory of Algorithms: Divide and Conquer
QuickSort 4 February QuickSort(S) Fast divide and conquer algorithm first discovered by C. A. R. Hoare in If the number of elements in.
DIVIDE AND CONQUER APPROACH. General Method Works on the approach of dividing a given problem into smaller sub problems (ideally of same size).  Divide.
ISOM MIS 215 Module 7 – Sorting. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Advanced Topics in Algorithms and Data Structures Lecture pg 1 Recursion.
Quicksort CS 3358 Data Structures. Sorting II/ Slide 2 Introduction Fastest known sorting algorithm in practice * Average case: O(N log N) * Worst case:
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 4 Some of the sides are exported from different sources.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Algorithm An algorithm is a step-by-step set of operations to be performed. Real-life example: a recipe Computer science example: determining the mode.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
1 Lecture 11 Sorting Parallel Computing Fall 2008.
CSCI 4440 / 8446 Parallel Computing Three Sorting Algorithms.
Functional Design and Programming Lecture 4: Sorting.
Sorting Lower Bound Andreas Klappenecker based on slides by Prof. Welch 1.
Chapter 7 (Part 2) Sorting Algorithms Merge Sort.
Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (I) Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
Sorting II/ Slide 1 Lecture 24 May 15, 2011 l merge-sorting l quick-sorting.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Computer Algorithms Lecture 10 Quicksort Ch. 7 Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
1 Divide and Conquer Binary Search Mergesort Recurrence Relations CSE Lecture 4 – Algorithms II.
Lecture 2 We have given O(n 3 ), O(n 2 ), O(nlogn) algorithms for the max sub-range problem. This time, a linear time algorithm! The idea is as follows:
Lecture 2 Computational Complexity
Lecture 8-1 : Parallel Algorithms (focus on sorting algorithms) Courtesy : Prof. Chowdhury(SUNY-SB) and Prof.Grossman(UW)’s course note slides are used.
Quick Sort By: HMA. RECAP: Divide and Conquer Algorithms This term refers to recursive problem-solving strategies in which 2 cases are identified: A case.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
September 17, 2001 Algorithms and Data Structures Lecture II Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
CSS106 Introduction to Elementary Algorithms M.Sc Askar Satabaldiyev Lecture 05: MergeSort & QuickSort.
Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2.Solve smaller instances.
Divide and Conquer Strategy
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
1 Ch. 2: Getting Started. 2 About this lecture Study a few simple algorithms for sorting – Insertion Sort – Selection Sort (Exercise) – Merge Sort Show.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
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.
QuickSort. Yet another sorting algorithm! Usually faster than other algorithms on average, although worst-case is O(n 2 ) Divide-and-conquer: –Divide:
CSCI-455/552 Introduction to High Performance Computing Lecture 21.
Lecture 6 Sorting II Divide-and-Conquer Algorithms.
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 8-1 : Parallel Algorithms (focus on sorting algorithms)
Warmup What is an abstract class?
Algorithm Design Methods
Unit-2 Divide and Conquer
CS200: Algorithms Analysis
Divide and Conquer Algorithms Part I
Chapter 4.
ITEC 2620M Introduction to Data Structures
Algorithm Efficiency and Sorting
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

Lecture 7 : Parallel Algorithms (focus on sorting algorithms) Courtesy : SUNY-Stony Brook Prof. Chowdhury’s course note slides are used in this lecture note

Parallel/Distributed Algorithms Parallel program(algorithm) A program (algorithm) is divided into multiple processes(threads) which are run on multiple processors The processors normally are in one machine execute one program at a time have high speed communications between them Distributed program(algorithm) A program (algorithm) is divided into multiple processes which are run on multiple distinct machines The multiple machines are usual connected by network. Machines used typically are workstations running multiple programs.

Divide-and-Conquer Divide divide the original problem into smaller subproblems that are easier are to solve Conquer solve the smaller subproblems (perhaps recursively) Merge combine the solutions to the smaller subproblems to obtain a solution for the original problem Can be extended to parallel algorithm

Divide-and-Conquer The divide-and-conquer paradigm improves program modularity, and often leads to simple and efficient algorithms Since the subproblems created in the divide step are often independent, they can be solved in parallel If the subproblems are solved recursively, each recursive divide step generates even more independent subproblems to be solved in parallel In order to obtain a highly parallel algorithm it is often necessary to parallelize the divide and merge steps, too

Example of Parallel Program (divide-and-conquer approach) spawn Subroutine can execute at the same time as its parent sync Wait until all children are done A procedure cannot safely use the return values of the children it has spawned until it executes a sync statement. Fibonacci(n) 1: if n < 2 2: return n 3: x = spawn Fibonacci(n-1) 4: y = spawn Fibonacci(n-2) 5: sync 6: return x + y

Performance Measure T p running time of an algorithm on p processors T 1 running time of algorithm on 1 processor T ∞ the longest time to execute the algorithm on infinite number of processors.

Performance Measure Lower bounds on T p T p >= T 1 / p T p >= T ∞ P processors cannot do more than infinite number of processors Speedup T 1 / T p : speedup on p processors Parallelism T 1 / T ∞ Max possible parallel speedup

Related Sorting Algorithms Sorting Algorithms Sort an array A[1,…,n] of n keys (using p<=n processors) Examples of divide-and-conquer methods Merge-sort Quick-sort

Merge-Sort Basic Plan Divide array into two halves Recursively sort each half Merge two halves to make sorted whole

Merge-Sort Algorithm

Performance analysis

Time Complexity Notation Asymptotic Notation ( 점근적 표기법 ) A way to describe the behavior of functions in the limit ( 어떤 함수의 인수값이 무한히 커질때, 그 함수의 증가율을 더 간단한 함수를 이용해 나타내는 것 )

Time Complexity Notation O notation – upper bound O(g(n)) = { h(n): ∃ positive constants c, n 0 such that 0 ≤ h(n) ≤ cg(n), ∀ n ≥ n 0 } Ω notation – lower bound Ω(g(n)) = {h(n): ∃ positive constants c > 0, n 0 such that 0 ≤ cg(n) ≤ h(n), ∀ n ≥ n 0 } Θ notation – tight bound Θ(g(n)) = {h(n): ∃ positive constants c 1, c 2, n 0 such that 0 ≤ c 1 g(n) ≤ h(n) ≤ c 2 g(n), ∀ n ≥ n 0 }

Parallel merge-sort

Performance Analysis Too small! Need to parallelize Merge step

Parallel Merge

Parallel merge

Parallel Merge

(Sequential) Quick-Sort algorithm a recursive procedure Select one of the numbers as pivot Divide the list into two sublists: a “low list” containing numbers smaller than the pivot, and a “high list” containing numbers larger than the pivot The low list and high list recursively repeat the procedure to sort themselves The final sorted result is the concatenation of the sorted low list, the pivot, and the sorted high list

(Sequential) Quick-Sort algorithm Given a list of numbers: {79, 17, 14, 65, 89, 4, 95, 22, 63, 11} The first number, 79, is chosen as pivot Low list contains {17, 14, 65, 4, 22, 63, 11} High list contains {89, 95} For sublist {17, 14, 65, 4, 22, 63, 11}, choose 17 as pivot Low list contains {14, 4, 11} High list contains {64, 22, 63}... {4, 11, 14, 17, 22, 63, 65} is the sorted result of sublist {17, 14, 65, 4, 22, 63, 11} For sublist {89, 95} choose 89 as pivot Low list is empty (no need for further recursions) High list contains {95} (no need for further recursions) {89, 95} is the sorted result of sublist {89, 95} Final sorted result: {4, 11, 14, 17, 22, 63, 65, 79, 89, 95}

Illustation of Quick-Sort

Randomized quick-sort Par-Randomized-QuickSort ( A[ q : r ] ) 1. n <- r ― q if n <= 30 then 3. sort A[ q : r ] using any sorting algorithm 4. else 5. select a random element x from A[ q : r ] 6. k <- Par-Partition ( A[ q : r ], x ) 7. spawn Par-Randomized-QuickSort ( A[ q : k ― 1 ] ) 8. Par-Randomized-QuickSort ( A[ k + 1 : r ] ) 9. sync Worst-Case Time Complexity of Quick-Sort : O(N^2) Average Time Complexity of Sequential Randomized Quick-Sort : O(NlogN) (recursion depth of line 7-8 is roughly O(logN). Line 5 takes O(N))

Parallel Randomized Quick-Sort

Parallel partition Recursive divide-and-conquer

Parallel Partition Algorithm Analysis

Prefix Sums

Performance analysis