CS483 Analysis of Algorithms Lecture 03 Divide-n-Conquer

Size: px
Start display at page:

Download "CS483 Analysis of Algorithms Lecture 03 Divide-n-Conquer"

Transcription

1 CS483 Analysis of Algorithms Lecture 03 Divide-n-Conquer Jyh-Ming Lien February 05, 2009 this lecture note is based on Algorithms by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani and to the Design and Analysis of Algorithms by Anany Levitin. Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 1

2 In this lecture we will two main topics: Sort and selection Mergesort and quicksort Binary search Closest-pair and convex-hull algorithms of large integers We will approach these problems using the divide-and-conquer technique Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 2

3 Divide and Conquer Divide and Conquer Divide and Conquer s Master Theorem Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 3

4 Divide and Conquer Divide and Conquer Divide and Conquer Divide and Conquer s Master Theorem Divide and conquer was a successful military strategy long before it became an algorithm design strategy Coalition uses divide-conquer plan in Fallujah By Rowan Scarborough and Bill Gertz, THE WASHINGTON TIMES Coalition troops are employing a divide-and-conquer strategy in Fallujah, Iraq, capitalizing on months of pinpointed intelligence to seal off terrorist-held neighborhoods and then attack enemy pockets. : Your CS 483 instructor give you a 50-question assignment today and ask you to turn it in the tomorrow. What should you do? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 4

5 Divide and Conquer Divide and Conquer Divide and Conquer Divide and Conquer s Master Theorem The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger) instance by combining these solutions Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 5

6 Divide and Conquer s Divide and Conquer Divide and Conquer Divide and Conquer s Master Theorem : Given a list A = {2,3,6,4,12,1,7}, compute 7 i=1 A i Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 6

7 Master Theorem Divide and Conquer Divide and Conquer Divide and Conquer s Master Theorem If we have a problem of size n and our algorithm divides the problems into b instances, with a of them needing to be solved. Then we can set up our running time T(n) as: T(n) = at(n/b) + f(n), where f(n) is the time spent on dividing and merging. Master Theorem: If f(n) Θ(n d ), with d 0, then Θ(n d ) if a < b d T(n) = Θ(n d log n) if a = b d Θ(n log b a ) if a > b d s: 1. T(n) = 4T(n/2) + n T(n) = 2. T(n) = 4T(n/2) + n 2 T(n) = 3. T(n) = 4T(n/2) + n 3 T(n) = Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 7

8 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 8

9 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Given an array of n numbers, sort the element from small to large. Algorithm 0.1: MERGESORT(A[1 n]) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 9

10 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Merge two sorted arrays, B and C and put the result in A Algorithm 0.2: MERGE(B[1 p], C[1 q], A[1 p + q]) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 10

11 : 24, 11, 91, 10, 22, 32, 22, 3, 7, 99 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Is Mergesort stable? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 11

12 Analysis of Merge Sort Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull C worst (n) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 12

13 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Given an array of n numbers, sort the element from small to large. Algorithm 0.3: QUICKSORT(A[1 n]) A[1] in the above algorithm is called pivot Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 13

14 : 24, 11, 91, 10, 22, 32, 22, 3, 7, 22 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Is Quicksort stable? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 14

15 Analysis of Quicksort Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull C worst (n) C best (n) C avg (n) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 15

16 Why is Quicksort quicker? Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Because quicksort allows very fast in-place partition Algorithm 0.4: PARTITION(A[a b]) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 16

17 The Selection Problem Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Similar to partition in quicksort! Find the k-th smallest element in an array A with n unique elements Algorithm 0.5: SELECT(A[1 n], k) The algorithm above will work well for A with unique elements. How do you change to make it work for more general cases? Time complexity: Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 17

18 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Imagine that you are placed in an unknown building and you are given a room number, you need to find your CS 483 instructor. What will you do? : Very efficient algorithm for searching in sorted array : find 70 in {3, 14, 27, 31, 39, 42, 55, 70, 74, 81, 85, 93, 98} Efficient search in even in high dimensional unknown space : Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 18

19 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Given a sorted array A of n numbers, find a key K in A Algorithm 0.6: BINARYSEARCH(A[1 n], K) Binary search is in fact a bad (degenerate) example of divide-and-conquer Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 19

20 Analysis of C worst (n) C best (n) C avg (n) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer note 1 of slide 19

21 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Find the closest distance between points in a given point set Algorithm 0.7: CP(P[1 n]) comment: P is a set n points Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 20

22 Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Find the closest distance between points in a given point set Algorithm 0.8: COMBINE(c, P, P 1, P 2, d) What is the time complexity? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 21

23 Convex Hull Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Here we consider a divide-and-conquer algorithm called quickhull Quickhull is similar to quicksort why? Observations (given a point set P in 2-d): The leftmost and rightmost points in P must be part of the convex hull The furthest point away from any line must be part of the convex hull Points in the triangle formed by any three points in P will not be part of the convex hull Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 22

24 Quickhull Analysis of Merge Sort Analysis of Quicksort Why is Quicksort quicker? The Selection Problem Convex Hull Quickhull Qhull Algorithm 0.9: QHULL(P[1 n]) comment: P is a set n points Animation: ah/alg anim/version1/quickhull.html Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 23

25 Analysis of Quickhull Worst case: Best case: Avg case: Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer note 1 of slide 23

26 Representing polynomial Polynomial evaluation Horner s Rule A closer look Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 24

27 Representing polynomial Polynomial evaluation Horner s Rule A closer look What is the time complexity of multiplying two integers using the algorithms we learned in elementary schools? : how do you compute this: ? Is there a better way of multiplying two intergers than this elementary-school method? Carl Friedrich Gauss ( ) discovered that AB = (a10 n 2 + b)(c10 n 2 + d) = : how do you compute this: ? Carl Friedrich Gauss Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 25

28 Representing polynomial Polynomial evaluation Horner s Rule A closer look Divid-and-conquer interger multiplication Algorithm 0.10: M(A[1 n], B[1 n]) What is the time complexity? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 26

29 Representing polynomial Polynomial evaluation Horner s Rule A closer look Strassen s Matrix : [ ] [ ] [ ] C11 C 12 A11 A = 12 B11 A 12 C 21 C 22 A 21 A 22 B 21 B 22 [ ] m1 + m = 4 m 5 + m 7 m 3 + m 5 m 2 + m 4 m 1 + m 3 m 2 + m 6 m 1 = (A 11 + A 22 )(B 11 + B 22 ) m 2 = (A 21 + A 22 )B 11 m 3 = A 11 (B 12 B 22 ) m 4 = A 22 (B 21 B 11 ) m 5 = (A 11 + A 12 )B 22 m 6 = (A 21 A 11 )(B 11 + B 12 ) m 7 = (A 12 A 22 )(B 21 + B 22 ) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 27

30 Representing polynomial Polynomial evaluation Horner s Rule A closer look What is the time complexity? Do you still remember what the time complexity of the brute-force algorithm is? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 28

31 Polynomial multiplication Representing polynomial Polynomial evaluation Horner s Rule A closer look two degree-n polynomials: A(x) = a n x n + a n 1 x n a 1 x + a 0 B(x) = b n x n + b n 1 x n b 1 x + b 0 of two degree-n polynomial C(x) = A(x)B(x) = c 2n x 2n + c 2n 1 x 2n c 1 x + c 0 The coefficient c k is: A brute force method for computing C(x) will have time complexity= Can we do better? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 29

32 Representing polynomial Representing polynomial Polynomial evaluation Horner s Rule A closer look Fact: A degree-n polynomial is uniquely defined by any n + 1 distinct points A degree-n polynomial A(x) can be represented by: We can convert between these two representations: 1.5cm The value representation allows us to develop faster algorithm! We only need 2n + 1 points for C(x) It s easy and efficient to generate these 2n + 1 points from A(x) and B(x) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 30

33 Representing polynomial Polynomial multiplication Polynomial evaluation Horner s Rule A closer look General idea: 1. Convert A and B to value representation (Evaluation) 2. Perform multiplication to obtain C in value representation 3. Convert C back to coefficient representation (Interpolation) Coefficient representation A(x) = a n x n + a n 1 x n a 1 x + a 0 B(x) = b n x n + b n 1 x n b 1 x + b 0 A(x 0 ),A(x 1 ),...,A(x 2n ) B(x 0 ), B(x 1 ),...,B(x 2n ) Value representation Evaluation O(n log n) O(n 2 ) O(n) C(x i ) = A(x i )B(x i ) C(x) = c 2n x 2n + c 2n 1 x 2n c 1 x + c 0 Interpolation O(n log n) C(x 0 ),C(x 1 ),...,C(x 2n ) Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 31

34 Polynomial evaluation Representing polynomial Polynomial evaluation Horner s Rule A closer look f(x) = a n x n + a n 1 x n a 1 x + a 0 Polynomial evaluation: Given x, compute f(x) Brute force algorithm Algorithm 0.11: F(x) Time complexity of this brute force algorithm? Can we do better? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 32

35 Horner s Rule Representing polynomial Polynomial evaluation Horner s Rule A closer look Horner s rule f(x) = a n x n + a n 1 x n a 1 x + a 0 = (a n x n 1 + a n 1 x n a 1 )x + a 0 = ( (a n x + a n 1 )x + )x + a 0 Polynomial evaluation using Horner s rule Algorithm 0.12: F(x) Time complexity: : f(x) = 2x 4 x 3 + 3x 2 + x 5 at x = 4 Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 33

36 Representing polynomial Polynomial evaluation Horner s Rule A closer look Basic idea: How we select x i affects the run time. : If we pick ±x 0, ±x 1,..., ±x n/2 1, then A(x i ) and A( x i ) have many overlap x 5 + 2x 4 + 3x 3 + 4x 2 + 5x + 6 = A(x) = When evaluate x i, A(x i ) = When evaluate x i, A( x i ) = What we need is x i such that Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 34

37 Representing polynomial Polynomial evaluation Horner s Rule A closer look Idea: Use : z n = 1 as our x i Background: Complex number z = r(cos(θ) + i sin(θ)) Usually denoted as re iθ or (r, θ) (r 1, θ 1 ) (r 2, θ 2 ) = (r 1 r 2, θ 1 + θ 2 ) Let ω n = cos( 2π n ) + isin(2π n ) = e2πi/n be a complex n-th root of unity Other roots include: ωn, 2 ωn, 3...,ωn n 1, ωn n Properties: ωn j = ωn j+n/2 Therefore, (ωn) j 2 = ( ωn j+n/2 ) 2 Moreover, (ωn) j 2 = ω j n/2 P n i=1 ωi n = 1 ωn n 1 ω n = 0 Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 35

38 Representing polynomial Polynomial evaluation Horner s Rule A closer look s n = 8: Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 36

39 Representing polynomial Polynomial evaluation Horner s Rule A closer look FFT Algorithm 0.13: FFT((a 0, a 1, a 2,..., a n 1 ), ω) Time complexity? Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 37

40 Representing polynomial Polynomial evaluation Horner s Rule A closer look Hardware implementation Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 38

41 Representing polynomial Polynomial evaluation Horner s Rule polynomial interpolation A closer look Convert the values C(x i ) back to coefficients: {c i }=FFT(C(x i ), ω 1) Here is why M n (ω) = Entry (j, k) of M n is ω jk Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 39

42 Representing polynomial Polynomial evaluation Horner s Rule polynomial interpolation A closer look M n (ω) is invertible, i.e., column j and column k are orthogonal proof: Inversion formula M n (ω) 1 = 1 n M n(ω 1 ) proof: Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 40

43 A closer look Representing polynomial Polynomial evaluation Horner s Rule A closer look Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 41

44 Summary Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 42

45 Summary Summary Summary Sort and select Mergesort and quicksort 1 Binary search Closest-pair and convex-hull algorithms of large integers - from Gauss - FFT 1 (Also from Gauss) Divide-n-conquer strategy Advantages of Make problems easier Easy parallelization Disadvantages of Divide-n-conquer strategy Recursion can be slow Subproblems may overlap 1 Named one of 10 best algorithms in last century Analysis of Algorithms CS483 Lecture 03-Divide-n-Conquer 43

CS Divide and Conquer

CS Divide and Conquer CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

CS Divide and Conquer

CS Divide and Conquer CS483-07 Divide and Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

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

Chapter 4. Divide-and-Conquer. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 4 Divide-and-Conquer Copyright 2007 Pearson Addison-Wesley. All rights reserved. Divide-and-Conquer The most-well known algorithm design strategy: 2. Divide instance of problem into two or more

More information

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions

Divide-and-Conquer. The most-well known algorithm design strategy: smaller instances. combining these solutions 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 recursively 3. Obtain solution to original

More information

CSC Design and Analysis of Algorithms

CSC Design and Analysis of Algorithms CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conquer Algorithm Design Technique Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer

Computer Science 385 Analysis of Algorithms Siena College Spring Topic Notes: Divide and Conquer Computer Science 385 Analysis of Algorithms Siena College Spring 2011 Topic Notes: Divide and Conquer Divide and-conquer is a very common and very powerful algorithm design technique. The general idea:

More information

Divide-and-Conquer. Dr. Yingwu Zhu

Divide-and-Conquer. Dr. Yingwu Zhu Divide-and-Conquer Dr. Yingwu Zhu Divide-and-Conquer The most-well known algorithm design technique: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances independently

More information

CS Elementary Graph Algorithms & Transform-and-Conquer

CS Elementary Graph Algorithms & Transform-and-Conquer CS483-10 Elementary Graph Algorithms & Transform-and-Conquer Outline Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments Depth-first Search cont Topological

More information

Divide and Conquer 4-0

Divide and Conquer 4-0 Divide and Conquer 4-0 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 recursively 3. Obtain

More information

CSCE 411 Design and Analysis of Algorithms

CSCE 411 Design and Analysis of Algorithms CSCE 411 Design and Analysis of Algorithms Set 3: Divide and Conquer Slides by Prof. Jennifer Welch Spring 2014 CSCE 411, Spring 2014: Set 3 1 General Idea of Divide & Conquer 1. Take your problem and

More information

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer Module 2: Divide and Conquer Divide and Conquer Control Abstraction for Divide &Conquer 1 Recurrence equation for Divide and Conquer: If the size of problem p is n and the sizes of the k sub problems are

More information

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort)

MA/CSSE 473 Day 17. Divide-and-conquer Convex Hull. Strassen's Algorithm: Matrix Multiplication. (if time, Shell's Sort) MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull Strassen's Algorithm: Matrix Multiplication (if time, Shell's Sort) MA/CSSE 473 Day 17 Student Questions Exam 2 specification Levitin 3 rd Edition Closest

More information

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer

CSC Design and Analysis of Algorithms. Lecture 6. Divide and Conquer Algorithm Design Technique. Divide-and-Conquer CSC 8301- Design and Analysis of Algorithms Lecture 6 Divide and Conuer Algorithm Design Techniue Divide-and-Conuer The most-well known algorithm design strategy: 1. Divide a problem instance into two

More information

Divide-and-Conquer CSE 680

Divide-and-Conquer CSE 680 Divide-and-Conquer CSE 680 1 Introduction Given an instance x of a problem, the divide-and-conquer method works as follows. function DAQ(x) if x is sufficiently small or simple then solve it directly else

More information

Divide and Conquer. Algorithm Fall Semester

Divide and Conquer. Algorithm Fall Semester Divide and Conquer Algorithm 2014 Fall Semester 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

More information

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1 DIVIDE & CONQUER Definition: Divide & conquer is a general algorithm design strategy with a general plan as follows: 1. DIVIDE: A problem s instance is divided into several smaller instances of the same

More information

Rec 8 Notes. 1 Divide-and-Conquer Convex Hull. 1.1 Algorithm Idea. 1.2 Algorithm. Here s another random Divide-And-Conquer algorithm.

Rec 8 Notes. 1 Divide-and-Conquer Convex Hull. 1.1 Algorithm Idea. 1.2 Algorithm. Here s another random Divide-And-Conquer algorithm. Divide-and-Conquer Convex Hull Here s another random Divide-And-Conquer algorithm. Recall, possibly from CS 2, that the convex hull H(Q) of a set of points Q is the smallest convex set containing Q (that

More information

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

Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2013/14 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

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

Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2015/16 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine

More information

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול

Advanced Algorithms. Problem solving Techniques. Divide and Conquer הפרד ומשול Advanced Algorithms Problem solving Techniques. Divide and Conquer הפרד ומשול 1 Divide and Conquer A method of designing algorithms that (informally) proceeds as follows: Given an instance of the problem

More information

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk 8/29/06 CS 6463: AT Computational Geometry 1 Convex Hull Problem Given a set of pins on a pinboard and a rubber band around them.

More information

CPSC 320 Midterm 2 Thursday March 13th, 2014

CPSC 320 Midterm 2 Thursday March 13th, 2014 CPSC 320 Midterm 2 Thursday March 13th, 2014 [12] 1. Answer each question with True or False, and then justify your answer briefly. [2] (a) The Master theorem can be applied to the recurrence relation

More information

Sorting and Selection

Sorting and Selection Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element

More information

CPS 616 TRANSFORM-AND-CONQUER 7-1

CPS 616 TRANSFORM-AND-CONQUER 7-1 CPS 616 TRANSFORM-AND-CONQUER 7-1 TRANSFORM AND CONQUER Group of techniques to solve a problem by first transforming the problem into one of: 1. a simpler/more convenient instance of the same problem (instance

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points randomized quicksort median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013

More information

SORTING AND SELECTION

SORTING AND SELECTION 2 < > 1 4 8 6 = 9 CHAPTER 12 SORTING AND SELECTION ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016)

More information

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

Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn Chapter 1 Divide and Conquer Algorithm Theory WS 2014/15 Fabian Kuhn Divide And Conquer Principle Important algorithm design method Examples from Informatik 2: Sorting: Mergesort, Quicksort Binary search

More information

EECS 2011M: Fundamentals of Data Structures

EECS 2011M: Fundamentals of Data Structures M: Fundamentals of Data Structures Instructor: Suprakash Datta Office : LAS 3043 Course page: http://www.eecs.yorku.ca/course/2011m Also on Moodle Note: Some slides in this lecture are adopted from James

More information

COMP 3403 Algorithm Analysis Part 2 Chapters 4 5. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University

COMP 3403 Algorithm Analysis Part 2 Chapters 4 5. Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University COMP 3403 Algorithm Analysis Part 2 Chapters 4 5 Jim Diamond CAR 409 Jodrey School of Computer Science Acadia University Chapter 4 Decrease and Conquer Chapter 4 43 Chapter 4: Decrease and Conquer Idea:

More information

Selection (deterministic & randomized): finding the median in linear time

Selection (deterministic & randomized): finding the median in linear time Lecture 4 Selection (deterministic & randomized): finding the median in linear time 4.1 Overview Given an unsorted array, how quickly can one find the median element? Can one do it more quickly than bysorting?

More information

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted.

A 0 A 1... A i 1 A i,..., A min,..., A n 1 in their final positions the last n i elements After n 1 passes, the list is sorted. CS6402 Design and Analysis of Algorithms _ Unit II 2.1 UNIT II BRUTE FORCE AND DIVIDE-AND-CONQUER 2.1 BRUTE FORCE Brute force is a straightforward approach to solving a problem, usually directly based

More information

CS 303 Design and Analysis of Algorithms

CS 303 Design and Analysis of Algorithms Mid-term CS 303 Design and Analysis of Algorithms Review For Midterm Dong Xu (Based on class note of David Luebke) 12:55-1:55pm, Friday, March 19 Close book Bring your calculator 30% of your final score

More information

CSC 1700 Analysis of Algorithms: Heaps

CSC 1700 Analysis of Algorithms: Heaps CSC 1700 Analysis of Algorithms: Heaps Professor Henry Carter Fall 2016 Recap Transform-and-conquer preprocesses a problem to make it simpler/more familiar Three types: Instance simplification Representation

More information

Lecture 8: Mergesort / Quicksort Steven Skiena

Lecture 8: Mergesort / Quicksort Steven Skiena Lecture 8: Mergesort / Quicksort Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Problem of the Day Give an efficient

More information

Data Structures and Algorithms CSE 465

Data Structures and Algorithms CSE 465 Data Structures and Algorithms CSE 465 LECTURE 4 More Divide and Conquer Binary Search Exponentiation Multiplication Sofya Raskhodnikova and Adam Smith Review questions How long does Merge Sort take on

More information

2. Instance simplification Solve a problem s instance by transforming it into another simpler/easier instance of the same problem

2. Instance simplification Solve a problem s instance by transforming it into another simpler/easier instance of the same problem CmSc 20 Intro to Algorithms Chapter 6. Transform and Conquer Algorithms. Introduction This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem

More information

CSC 8301 Design and Analysis of Algorithms: Heaps

CSC 8301 Design and Analysis of Algorithms: Heaps CSC 8301 Design and Analysis of Algorithms: Heaps Professor Henry Carter Fall 2016 Recap Transform-and-conquer preprocesses a problem to make it simpler/more familiar Three types: Instance simplification

More information

Algorithm Design Techniques part I

Algorithm Design Techniques part I Algorithm Design Techniques part I Divide-and-Conquer. Dynamic Programming DSA - lecture 8 - T.U.Cluj-Napoca - M. Joldos 1 Some Algorithm Design Techniques Top-Down Algorithms: Divide-and-Conquer Bottom-Up

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 13 Divide and Conquer Closest Pair of Points Convex Hull Strassen Matrix Mult. Adam Smith 9/24/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova,

More information

Sorting. There exist sorting algorithms which have shown to be more efficient in practice.

Sorting. There exist sorting algorithms which have shown to be more efficient in practice. Sorting Next to storing and retrieving data, sorting of data is one of the more common algorithmic tasks, with many different ways to perform it. Whenever we perform a web search and/or view statistics

More information

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

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Sorting lower bound and Linear-time sorting Date: 9/19/17 5.1 Introduction You should all know a few ways of sorting in O(n log n)

More information

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

The Limits of Sorting Divide-and-Conquer Comparison Sorts II The Limits of Sorting Divide-and-Conquer Comparison Sorts II CS 311 Data Structures and Algorithms Lecture Slides Monday, October 12, 2009 Glenn G. Chappell Department of Computer Science University of

More information

Mergesort again. 1. Split the list into two equal parts

Mergesort again. 1. Split the list into two equal parts Quicksort Mergesort again 1. Split the list into two equal parts 5 3 9 2 8 7 3 2 1 4 5 3 9 2 8 7 3 2 1 4 Mergesort again 2. Recursively mergesort the two parts 5 3 9 2 8 7 3 2 1 4 2 3 5 8 9 1 2 3 4 7 Mergesort

More information

CSC Design and Analysis of Algorithms. Lecture 8. Transform and Conquer II Algorithm Design Technique. Transform and Conquer

CSC Design and Analysis of Algorithms. Lecture 8. Transform and Conquer II Algorithm Design Technique. Transform and Conquer CSC 301- Design and Analysis of Algorithms Lecture Transform and Conquer II Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more

More information

Lecture 7. Transform-and-Conquer

Lecture 7. Transform-and-Conquer Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Lecture 7 - Jan. 17, 2018 CLRS 7.1, 7-4, 9.1, 9.3 University of Manitoba COMP 3170 - Analysis of Algorithms & Data Structures 1 / 11 QuickSelect

More information

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS

LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS Department of Computer Science University of Babylon LECTURE NOTES OF ALGORITHMS: DESIGN TECHNIQUES AND ANALYSIS By Faculty of Science for Women( SCIW), University of Babylon, Iraq Samaher@uobabylon.edu.iq

More information

Lecture 9: Sorting Algorithms

Lecture 9: Sorting Algorithms Lecture 9: Sorting Algorithms Bo Tang @ SUSTech, Spring 2018 Sorting problem Sorting Problem Input: an array A[1..n] with n integers Output: a sorted array A (in ascending order) Problem is: sort A[1..n]

More information

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola

How fast can we sort? Sorting. Decision-tree example. Decision-tree example. CS 3343 Fall by Charles E. Leiserson; small changes by Carola CS 3343 Fall 2007 Sorting Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 3343 Analysis of Algorithms 1 How fast can we sort? All the sorting algorithms we have seen

More information

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

Sorting Algorithms. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Sorting Algorithms CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 QuickSort Divide-and-conquer approach to sorting Like

More information

Divide and Conquer. Divide and Conquer

Divide and Conquer. Divide and Conquer October 6, 2017 Divide and Conquer Chapter 2 of Dasgupta et al. 1 Divide and Conquer Divide: If the input size is too large to deal with in a straightforward manner, divide the data into two or more disjoint

More information

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

Plotting run-time graphically. Plotting run-time graphically. CS241 Algorithmics - week 1 review. Prefix Averages - Algorithm #1 CS241 - week 1 review Special classes of algorithms: logarithmic: O(log n) linear: O(n) quadratic: O(n 2 ) polynomial: O(n k ), k 1 exponential: O(a n ), a > 1 Classifying algorithms is generally done

More information

CSC Design and Analysis of Algorithms

CSC Design and Analysis of Algorithms CSC : Lecture 7 CSC - Design and Analysis of Algorithms Lecture 7 Transform and Conquer I Algorithm Design Technique CSC : Lecture 7 Transform and Conquer This group of techniques solves a problem by a

More information

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

The divide and conquer strategy has three basic parts. For a given problem of size n, 1 Divide & Conquer One strategy for designing efficient algorithms is the divide and conquer approach, which is also called, more simply, a recursive approach. The analysis of recursive algorithms often

More information

Divide & Conquer. 2. Conquer the sub-problems by solving them recursively. 1. Divide the problem into number of sub-problems

Divide & Conquer. 2. Conquer the sub-problems by solving them recursively. 1. Divide the problem into number of sub-problems Divide & Conquer Divide & Conquer The Divide & Conquer approach breaks down the problem into multiple smaller sub-problems, solves the sub-problems recursively, then combines the solutions of the sub-problems

More information

Divide and Conquer. Algorithm D-and-C(n: input size)

Divide and Conquer. Algorithm D-and-C(n: input size) Divide and Conquer Algorithm D-and-C(n: input size) if n n 0 /* small size problem*/ Solve problem without futher sub-division; else Divide into m sub-problems; Conquer the sub-problems by solving them

More information

CS Transform-and-Conquer

CS Transform-and-Conquer CS483-11 Transform-and-Conquer Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

CSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer

CSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer // CSC - Design and Analysis of Algorithms Lecture 7 Transform and Conquer I Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more

More information

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today Recursive Sorting Methods and their Complexity: Mergesort Conclusions on sorting algorithms and complexity Next Time:

More information

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College Convex Hull Given a set P of points in 2D, their convex hull is the smallest convex polygon that contains all points

More information

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook by Dr. Y.

More information

4.4 Algorithm Design Technique: Randomization

4.4 Algorithm Design Technique: Randomization TIE-20106 76 4.4 Algorithm Design Technique: Randomization Randomization is one of the design techniques of algorithms. A pathological occurence of the worst-case inputs can be avoided with it. The best-case

More information

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

CSE 3101: Introduction to the Design and Analysis of Algorithms. Office hours: Wed 4-6 pm (CSEB 3043), or by appointment. CSE 3101: Introduction to the Design and Analysis of Algorithms Instructor: Suprakash Datta (datta[at]cse.yorku.ca) ext 77875 Lectures: Tues, BC 215, 7 10 PM Office hours: Wed 4-6 pm (CSEB 3043), or by

More information

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Acknowledgement. Outline

Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Acknowledgement. Outline Divide and Conquer CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Acknowledgement The set of slides have use materials from the following resources Slides for textbook by Dr. Y.

More information

Randomized Algorithms, Quicksort and Randomized Selection

Randomized Algorithms, Quicksort and Randomized Selection CMPS 2200 Fall 2017 Randomized Algorithms, Quicksort and Randomized Selection Carola Wenk Slides by Carola Wenk and Charles Leiserson CMPS 2200 Intro. to Algorithms 1 Deterministic Algorithms Runtime for

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 16 Dynamic Programming (plus FFT Recap) Adam Smith 9/24/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Discrete Fourier Transform

More information

Quicksort (Weiss chapter 8.6)

Quicksort (Weiss chapter 8.6) Quicksort (Weiss chapter 8.6) Recap of before Easter We saw a load of sorting algorithms, including mergesort To mergesort a list: Split the list into two halves Recursively mergesort the two halves Merge

More information

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

Practical Session #11 - Sort properties, QuickSort algorithm, Selection Practical Session #11 - Sort properties, QuickSort algorithm, Selection Quicksort quicksort( A, low, high ) if( high > low ) pivot partition( A, low, high ) // quicksort( A, low, pivot-1 ) quicksort( A,

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................

More information

Lower Bound on Comparison-based Sorting

Lower Bound on Comparison-based Sorting Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting

More information

Sorting Algorithms. For special input, O(n) sorting is possible. Between O(n 2 ) and O(nlogn) E.g., input integer between O(n) and O(n)

Sorting Algorithms. For special input, O(n) sorting is possible. Between O(n 2 ) and O(nlogn) E.g., input integer between O(n) and O(n) Sorting Sorting Algorithms Between O(n ) and O(nlogn) For special input, O(n) sorting is possible E.g., input integer between O(n) and O(n) Selection Sort For each loop Find max Swap max and rightmost

More information

4. Sorting and Order-Statistics

4. Sorting and Order-Statistics 4. Sorting and Order-Statistics 4. Sorting and Order-Statistics The sorting problem consists in the following : Input : a sequence of n elements (a 1, a 2,..., a n ). Output : a permutation (a 1, a 2,...,

More information

CS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Wednesday, October 17, 2012.

CS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Wednesday, October 17, 2012. CS 411 Analysis of Algorithms, Fall 2012 Midterm Exam Solutions The Midterm Exam was given in class on Wednesday, October 17, 2012. A1. Time Complexity. In each part, indicate the (time) order of a fast

More information

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

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

CS 372: Computational Geometry Lecture 3 Line Segment Intersection CS 372: Computational Geometry Lecture 3 Line Segment Intersection Antoine Vigneron King Abdullah University of Science and Technology September 9, 2012 Antoine Vigneron (KAUST) CS 372 Lecture 3 September

More information

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.

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. Problem 5. Sorting Simple Sorting, Quicksort, Mergesort 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. 98 99 Selection Sort

More information

Unit-2 Divide and conquer 2016

Unit-2 Divide and conquer 2016 2 Divide and conquer Overview, Structure of divide-and-conquer algorithms, binary search, quick sort, Strassen multiplication. 13% 05 Divide-and- conquer The Divide and Conquer Paradigm, is a method of

More information

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Chapter 3:- Divide and Conquer. Compiled By:- Sanjay Patel Assistant Professor, SVBIT. Chapter 3:- Divide and Conquer Compiled By:- Assistant Professor, SVBIT. Outline Introduction Multiplying large Integers Problem Problem Solving using divide and conquer algorithm - Binary Search Sorting

More information

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

CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting. Aaron Bauer Winter 2014 CSE373: Data Structure & Algorithms Lecture 21: More Comparison Sorting Aaron Bauer Winter 2014 The main problem, stated carefully For now, assume we have n comparable elements in an array and we want

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 Date : 30/3/15 Max Marks : 50 Name of faculty : Sabeeha Sultana Subject & Code : ADA(13MCA41) Answer any five full question: 1.Illustrate Mergesort for the dataset 8,3,2,9,7,1,5,4.

More information

Analysis of Algorithms - Quicksort -

Analysis of Algorithms - Quicksort - Analysis of Algorithms - Quicksort - Andreas Ermedahl MRTC (Mälardalens Real-Time Reseach Center) andreas.ermedahl@mdh.se Autumn 2003 Quicksort Proposed by C.A.R. Hoare in 962. Divide- and- conquer algorithm

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 12: Sorting Algorithms MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Outline 2 Last week Implementation of the three tree depth-traversal algorithms Implementation of the BinarySearchTree

More information

SORTING, SETS, AND SELECTION

SORTING, SETS, AND SELECTION CHAPTER 11 SORTING, SETS, AND SELECTION ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM

More information

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place?

Sorting. Sorting in Arrays. SelectionSort. SelectionSort. Binary search works great, but how do we create a sorted array in the first place? Sorting Binary search works great, but how do we create a sorted array in the first place? Sorting in Arrays Sorting algorithms: Selection sort: O(n 2 ) time Merge sort: O(nlog 2 (n)) time Quicksort: O(n

More information

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes

CS583 Lecture 01. Jana Kosecka. some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes CS583 Lecture 01 Jana Kosecka some materials here are based on Profs. E. Demaine, D. Luebke A.Shehu, J-M. Lien and Prof. Wang s past lecture notes Course Info course webpage: - from the syllabus on http://cs.gmu.edu/

More information

Simple Sorting Algorithms

Simple Sorting Algorithms Simple Sorting Algorithms Outline We are going to look at three simple sorting techniques: Bubble Sort, Selection Sort, and Insertion Sort We are going to develop the notion of a loop invariant We will

More information

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS

PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?

More information

Test 1 Review Questions with Solutions

Test 1 Review Questions with Solutions CS3510 Design & Analysis of Algorithms Section A Test 1 Review Questions with Solutions Instructor: Richard Peng Test 1 in class, Wednesday, Sep 13, 2017 Main Topics Asymptotic complexity: O, Ω, and Θ.

More information

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation)

MA/CSSE 473 Day 12. Questions? Insertion sort analysis Depth first Search Breadth first Search. (Introduce permutation and subset generation) MA/CSSE 473 Day 12 Interpolation Search Insertion Sort quick review DFS, BFS Topological Sort MA/CSSE 473 Day 12 Questions? Interpolation Search Insertion sort analysis Depth first Search Breadth first

More information

Lower bound for comparison-based sorting

Lower bound for comparison-based sorting COMP3600/6466 Algorithms 2018 Lecture 8 1 Lower bound for comparison-based sorting Reading: Cormen et al, Section 8.1 and 8.2 Different sorting algorithms may have different running-time complexities.

More information

Questions Total Points Score

Questions Total Points Score HKUST Department of Computer Science and Engineering # COMP3711H: Honors Design and Analysis of Algorithms Fall 2016 Midterm Examination Date: Thursday, Oct. 20, 2016 Time: 19:00 21:00 Venue: Room 2304

More information

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9)

CPSC 311 Lecture Notes. Sorting and Order Statistics (Chapters 6-9) CPSC 311 Lecture Notes Sorting and Order Statistics (Chapters 6-9) Acknowledgement: These notes are compiled by Nancy Amato at Texas A&M University. Parts of these course notes are based on notes from

More information

CS483 Analysis of Algorithms Lecture 09 Linear Programming 01

CS483 Analysis of Algorithms Lecture 09 Linear Programming 01 CS483 Analysis of Algorithms Lecture 09 Linear Programming 01 Jyh-Ming Lien April 09, 2009 this lecture note is based on Algorithms by S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani and to the Design

More information

Biostatistics 615/815 Lecture 5: Divide and Conquer Algorithms Sorting Algorithms

Biostatistics 615/815 Lecture 5: Divide and Conquer Algorithms Sorting Algorithms Biostatistics 615/815 Lecture 5: Algorithms Algorithms Hyun Min Kang September 20th, 2011 Hyun Min Kang Biostatistics 615/815 - Lecture 5 September 20th, 2011 1 / 30 Recap - An example C++ class #include

More information

Algorithms and Data Structures for Mathematicians

Algorithms and Data Structures for Mathematicians Algorithms and Data Structures for Mathematicians Lecture 5: Sorting Peter Kostolányi kostolanyi at fmph and so on Room M-258 26 October 2017 Sorting Algorithms Covered So Far Worst-case time complexity

More information

CS 140 : Non-numerical Examples with Cilk++

CS 140 : Non-numerical Examples with Cilk++ CS 140 : Non-numerical Examples with Cilk++ Divide and conquer paradigm for Cilk++ Quicksort Mergesort Thanks to Charles E. Leiserson for some of these slides 1 Work and Span (Recap) T P = execution time

More information

Reading for this lecture (Goodrich and Tamassia):

Reading for this lecture (Goodrich and Tamassia): COMP26120: Algorithms and Imperative Programming Basic sorting algorithms Ian Pratt-Hartmann Room KB2.38: email: ipratt@cs.man.ac.uk 2017 18 Reading for this lecture (Goodrich and Tamassia): Secs. 8.1,

More information

UNIT-2 DIVIDE & CONQUER

UNIT-2 DIVIDE & CONQUER Overview: Divide and Conquer Master theorem Master theorem based analysis for Binary Search Merge Sort Quick Sort Divide and Conquer UNIT-2 DIVIDE & CONQUER Basic Idea: 1. Decompose problems into sub instances.

More information