Design and Analysis of Algorithms

Size: px
Start display at page:

Download "Design and Analysis of Algorithms"

Transcription

1 CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 4: Divide and Conquer (I) Class URL:

2 Divide and Conquer ( DQ ) First paradigm or framework DQ(S) if S is small return ADHOC(S) else decompose S into subproblems S 1,, S k // divide for i = 1 to k do y i = DQ(S i ) // conquer recombine y i into solution y // compose return y Universal method : Mergesort, Quicksort, FFT, Matrix/Integer arithmetic are classic examples

3 DQ for Sorting From CSE 21 Divide (into two equal parts) Conquer (solve for each part separately) Combine separate solutions Mergesort Divide into two equal parts Sort each part using Mergesort (recursion!!!) Merge two sorted subsequences (Note: Quicksort is another DQ algorithm for sorting)

4 Merging Two Subsequences From CSE 21 Sequence #1: x[1], x[2],, x[m] Sequence #2: y[1], y[2],, y[n] if y[i] < x[j] then compare y[i+1] and x[j], else compare y[i] and x[j+1] After comparing x[1] and y[1], we advance in x[.] and y[.] a total of (m-1) + (n-1) times m + n - 1 comparisons (edges between red and blue) = linear time

5 Mergesort Tree of Recursive Subproblems DIVIDE log n log n CONQUER, COMBINE (n comparisons per level) X (log n levels) = (n log n runtime)

6 Integer Multiplication From CSE 21 Multiplying Large Integers (Karatsuba-Ofman) A = r n-1 a n r 1 a 1 + a 0, r = radix Classic approach = what you learned 12 years ago a n-1 a n-2 a 1 a 0 X b n-1 b n-2 b 1 b (n 2 ) work

7 (Unhelpful) DQ for Integer Multiplication Can we apply D/Q? Let n = 2s, r = 10 radix A = wx, B = yz AB = xz + 10 s (wz + xy) s wy Complexity analysis 4 n/2-digit multiplications: xz, wz, xy, wy Digit-shifting: multiplication by 10 s, 10 2s 3 additions T(n) = 4T(n/2) + (n) T(n) 4 T(n/2) + cn 4 [ 4T(n/4) + cn/2] + cn = 16 T(n/4) + (1 + 2)cn 16 [4T(n/8) + cn/4] + (1 + 2)cn = 64 T(n/8) + ( )cn 4 k T(n/2 k ) + ( k-1 )cn For k = log 2 n: T(n) n 2 T(1) + cn 2 = O(n 2 )

8 From CSE 21 Multiplication: HOW Divide and conquer? Divide n-digit numbers into two n/2-digit numbers. If a = and b = , we can write To multiply: a = (1234) * (5678) b = (2468) * (1357) ((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678)

9 From CSE 21 One 8-digit multiplication Multiplication: WHEN ( )( )=((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678) Four 4-digit multiplications (plus some shifts, sums)

10 (Helpful) DQ for Integer Multiplication Observation: r = (w+x)(y+z) = wy + (wz+xy) + xz r (w+x)(y+z) p wy q xz return 10 2s p + 10 s (r -p-q) + q What is (x n 1) / (x 1)? T(n) = 3T(n/2) + (n) T(n) 3 T(n/2) + cn 3 [ 3T(n/4) + cn/2] + cn = 9 T(n/4) + (1 + 3/2)cn 9 [3T(n/8) + cn/4] + (1 + 3/2)cn = 27 T(n/8) + (1 + 3/2 + 9/4)cn 3 k T(n/2 k ) + (1 + 3/2 + 9/4 + + (3/2) k-1 )cn For k = log 2 n: T(n) 3 log 2n T(1) + cn 2 (3/2) log 2n = O(3 log 2n ) = O(n log 23 ) = O(n ) [(3/2) k 1] / (3/2 1) = 2[(3/2) k 1] a log bc = c log ba (Take log base b)

11 Karatsuba Multiplication: HOW From CSE 21 Rosen p. 528 ( )( )=((1234) * (5678))((2468) * (1357))= (1234)(2468) * (1234)(1357) * (2468)(5678) * (1357)(5678) (1234)(2468) * ( ) + [(1234) - (5678)][ (1357)-(2468) ]* (1357)(5678) * ( ) Insight: replace one (of the 4) multiplications by (linear time) subtraction

12 Karatsuba Multiplication: WHEN From CSE 21 Instead of Rosen p. 528 T(n) = 4 T(n/2) + cn T K (n) = 3 T K (n/2) + pn with c a constant, now we have with p a constant.

13 Matrix Multiplication A = [ ], B = [ ] are n x n matrices a 11, a 12, etc are n/2 x n/2 submatrices M = AB = [ ] where m 11 = a 11 b 11 + a 12 b 21 etc. Evaluation requires 8 multiplies, 4 adds T(n) = 8T(n/2) + O(n 2 ) (n 3 ) (will see why later) a 11 a 12 a 21 a 22 b 11 b 12 X = b 21 b 22 m 11 m 12 m 21 m 22

14 Strassen s Matrix Multiplication p 1 = (a 21 + a 22 -a 11 )(b 22 -b 12 + b 11 ) p 2 = a 11 b 11 p 3 = a 12 b 21 p 4 = (a 11 -a 21 )(b 22 -b 12 ) p 5 = (a 21 +a 22 )(b 12 -b 11 ) p 6 = (a 12 -a 21 +a 11 -a 22 )b 22 p 7 = a 22 (b 11 +b 22 -b 12 -b 21 ) AB 11 = p 2 + p 3 AB 12 = p 1 + p 2 + p 5 + p 6 AB 21 = p 1 + p 2 + p 4 + p 7 AB 22 = p 1 + p 2 + p 4 + p 5 T(n) = 7T(n/2) + O(n) // 7 multiplies, 24 adds Can get to 15 adds (n 2.81 ) (will see why later)

15 General Formula (aka Master Theorem ) Recurrence T(n) a T(n/b) + O(n d ) From CSE 21 1) T(n) = O(n d ) if a < b d 2) T(n) = O(n d log n) if a = b d 3) T(n) = O(n log ba ) if a > b d Type (3): integer multiplication, Strassen Type (2): mergesort

16 Master Theorem Examples Mergesort T(n) = 2T(n/2) + (n) T ( n) ( n log n) Strassen Matrix Multiply T(n) = 7T(n/2) + (n 2 ) T ( n) 7 ( n log 2 ) ( n )

17 Recurrence: T(n) a T(n/b) + O(n d ) Anatomy of the Master Theorem

18 Anatomy of the Master Theorem T(n) a T(n/b) + O(n d ) Understand this picture and the notation conventions! n is the ( original, parent ) instance size a is the branching factor (i.e., number of subproblems created from a given problem) This is inherent to the recurrence for T(n) b is the size decrease factor E.g., b = 2 when subproblems are half the size of their parent problem d is the exponent in the + O(n d ) term of the recurrence

19 Anatomy of the Master Theorem T(n) a T(n/b) + O(n d ) We will assume for convenience that n is a power of b. So, the following will ignore rounding in n/b Since subproblem size decreases by factor of b with each level of recursion, we reach the base case (size = 1) after log b n levels Since the branching factor = a, at the k th level of the tree of recursive calls, there are a k subproblems, each of size n/b k

20 Anatomy of the Master Theorem T(n) a T(n/b) + O(n d ) Accounting When solving an instance of size = n, we pay O(n d ) work. Work done inside the a recursive calls of instance size n/b is accounted for with those calls. From previous slide: at the k th level of this tree of recursive calls, there are a k subproblems, each of size n/b k Total work done at the k th level: a k x O(n/b k ) d = O(n d ) x (a / b d ) k

21 Anatomy of the Master Theorem T(n) a T(n/b) + O(n d ) Total work done at the k th level: a k x O(n/b k ) d = O(n d ) x (a / b d ) k To add up total work done, we sum up over all levels This means summing a geometric series with ratio a / b d Terms of the series are of form (a / b d ) k We sum over all levels from k = 0 (at root of tree) to k = log b n (at the leaves)

22 Anatomy of the Master Theorem Summing A Geometric Series We want to evaluate: k = 0,, logb n O(n d ) x (a / b d ) k = O(n d ) x k = 0,, logb n (a / b d ) k If (a / b d ) < 1, the series converges and k = 0,, logb n (a / b d ) k is bounded by a constant. Letting r = a / b d, k = 0,, logb n r k k = 0,, r k = 1/(1 r) So, k = 0,, logb n O(n d ) x (a / b d ) k = O(n d )

23 Anatomy of the Master Theorem Summing A Geometric Series We want to evaluate: k = 0,, logb n O(n d ) x (a / b d ) k If (a / b d ) = 1, the sum is O(n d ) x log b n

24 Anatomy of the Master Theorem Summing A Geometric Series We want to evaluate: k = 0,, logb n O(n d ) x (a / b d ) k If (a / b d ) > 1, the series diverges and the sum is dominated by the last term. We get O(n d ) x (a / b d ) log bn = O(n d ) x (a log bn ) / (b d ) log bn = O(n d ) x (a log bn ) / (b d ) log bn See A Fact About Logarithms, next slide = O(n d ) x (a log bn ) / b d log bn = O(n d ) x (a log bn ) / n d = O(n log ba )

25 Proof of Master Theorem for Recurrences Recurrence T(n) a T(n/b) + O(n d ) 1) T(n) = O(n d ) if a < b d 2) T(n) = O(n d log n) if a = b d 3) T(n) = O(n log ba ) if a > b d Assume n is a power of b can ignore rounding in n/b Subproblem size decreases by factor of b with each level of recursion reaches base case after log b n levels Branching factor a k th level of tree has a k subproblems each of size n/b k Total work done at k th level is a k x O(n/b k ) d = O(n d ) x (a / b d ) k

26 Proof of Master Theorem for Recurrences Recurrence T(n) a T(n/b) + O(n d ) 1) T(n) = O(n d ) if a < b d 2) T(n) = O(n d log n) if a = b d 3) T(n) = O(n log ba ) if a > b d Total work done at k th level is a k x O(n/b k ) d = O(n d ) x (a / b d ) k As k goes from 0 (root) to log b n (leaves), have geometric series with ratio a / b d a / b d < 1 sum is O(n d ) a / b d > 1 sum is given by last term, O(n log ba ) a / b d = 1 sum is given by O(log n) terms equal to O(n d )

27 Discussion of Lower Bounds Lower bounds are useful Know that you can t do any better than a certain algorithmic (time, space, etc.) complexity Lower bounds can be migrated from one problem to another, via a type of argument called reduction Roughly: We know that problem A has complexity lower bound X. But, I can solve any instance of A using a solver for problem B. Therefore, problem B must also have complexity lower bound X. We will see a lot of reductions if/when we discuss NP-completeness later this quarter

28 Convex Hull (Lecture 1, Slide 32) Given a planar pointset S, its convex hull consists of all extreme points, i.e., points of S that cannot be expressed as convex combinations of any other points of S If you put a rubber band around the pointset, where does it snap tight?

29 Convex Hull Task: Return points in convex hull of S in order What is a lower bound on complexity? Q: If sorting requires (n log n) time, then why MUST convex hull also require (n log n) time? // will return to this How would you go about finding the convex hull?

30 Convex Hull (1) Task: Return points in convex hull of S in order Many known approaches: Giftwrap O(n 2 ) (O(nh)) Graham Scan O(n log n) D/Q O(n log n) Algorithm by Preparata and Hong left-right split find convex hulls merge convex hulls

31 Convex Hull (2) Task: Return points in convex hull of S in order Many known approaches: Giftwrap O(n 2 ) (O(nh)) Graham Scan O(n log n) D/Q O(n log n) Algorithm by Preparata and Hong left-right split find convex hulls merge convex hulls

32 Convex Hull (3) Task: Return points in convex hull of S in order Many known approaches: Giftwrap O(n 2 ) (O(nh)) Graham Scan O(n log n) D/Q O(n log n) Algorithm by Preparata and Hong left-right split find convex hulls merge convex hulls

33 A Lower Bound on Convex Hull Task: sort the set of numbers {3,1,4,5,2} Task: find the convex hull of the set of points {(3,9), (1,1), (4,16), (5,25), (2,4)}

34 A Lower Bound on Convex Hull Given: Sorting LB is (n log n) Reduction from Sorting to Convex Hull Input: an arbitrary instance I SORT of SORT Transform I SORT = {x 1, x 2,, x n } into an instance I C-HULL = {(x 1,x 12 ), (x 2,x 22 ),, (x n,x n2 )} of C-HULL Solve the C-HULL problem for instance I C-HULL Transform solution of I C-HULL to solution of I SORT

35 A Lower Bound on Convex Hull Given: Sorting LB is (n log n) Reduction from Sorting to Convex Hull Input: an arbitrary instance I SORT of SORT Transform I SORT = {x 1, x 2,, x n } into an instance I C-HULL = {(x 1,x 12 ), (x 2,x 22 ),, (x n,x n2 )} of C-HULL Solve the C-HULL problem for instance I C-HULL Transform solution of I C-HULL to solution of I SORT SORT input TX O(n) C-HULL input C-HULL solver C-HULL solution TX O(n) SORT solution SORT solver (n log n) Note: Each Transform has O(n) complexity C-HULL solver cannot be faster than (n log n)

36 The Closest Pair Problem Closest Pair: Given n points in the plane, return the closest pair Naïve (n 2 ) D/Q Approach: (n log n) (1) Split into two pointsets S 1, S 2 by x-coord natural order (2) Find closest pair distances d 1, d 2 in S 1, S 2 respectively without loss of generality, can assume d 1 <d 2 (3) Merge the solutions Do we have to check all s 1 -s 2 pairs, s 1 S 1, s 2 S 2? What if there are lots of points in middle strip? Key: Step (3) Observation: There are at most O(1) points in middle strip with y d 1

37 DQ Closest Pair (1) sort by x- and y-coords tool: one-time sort O(n log n) (2) solve subproblems of size n/2 2T(n/2) (3) eliminate points outside strips O(n) (4) sort by y-coord within strips O(n) (5) compare each point to 6 neighbors O(n) Complexity O(n log n) + T(n) = 2T(n/2) + O(n) T(2) = 1 T(n) O(n log n) Again, with one-time sort, can always output subproblems in y-sorted order

38 DQ Closest Pair Comment Note that we exploited geometry Example: what is the maximum possible degree of a vertex in a minimum spanning tree? If the problem is geometric? planar pointset If the problem is non-geometric? edge-weighted graph

39 The Selection Problem The SELECTION problem Given a list L and a number k Select (L, k) returns the k th smallest element of L What is an efficient algorithm? Note: if k = L /2, then Select(L,k) returns the median Note: Sorting + finding k th smallest O(n log n) Can do better using DQ (maybe, recalling idea of QSort pivot )

40 DQ Selection Pick a value v Split S into three parts: S <v, S =v, S >v Select (S,k) = Select(S <v,k) if k S <v (look in left) v if S <v < k S <v + S =v Select(S >v,k - S <v - S =v ) if k > S <v + S =v (look in right) Single split operation effectively reduces size of search space balanced By how much? Depends on v!!! If we could magically pick v so that S <v, S >v S /2 then we would have T(n) T(n/2) + O(n) T(n) = O(n) Time on array of size n Time for Split

41 EXTRA SLIDES

42 Sorting (With Comparisons) Input: sequence of numbers Output: a sorted sequence Observe: Sorting == Identifying a Permutation KEY OBSERVATIONS B < C Y A < B N A < C 1. We need at least as many leaves in this tree as there are possible outcomes (= n! permutations of n elements) 2. The number of comparisons needed to get to the leaf at greatest depth from the root is the worst-case complexity of the algorithm that is embodied by this comparison tree Y N Y N A < B < C A < C B < A < C B < C Y N Y N A < C < B C < A < B B < C < A C < B < A

43 Searching an Ordered List Input: ordered list L of n numbers, and a target number x Output: Find x if it exists in L Observe: Searching == Identifying the index of x in L Y Y x < L[n/4] N x < L[n/2] N x < L[3n/4] Y N KEY OBSERVATIONS 1. We generally use binary search, which takes log(n) time in the worst case. Why is binary search the best possible strategy? (*) 2. The number of comparisons needed to get to the leaf at greatest depth from the root is the worst-case complexity of the algorithm that is embodied by this comparison tree 3. Need at least n leaves 4. Height of comparison tree is (log n) (*) Interpolation Search is better than binary search when we know something about the distribution of the elements we are searching. For example, when humans use Interpolation Search when looking up something in a dictionary or a phone book.

44 A Lower Bound on Sorting Complexity In the comparison model of computation, can we find a lower bound on the complexity of sorting? From last slide: Sorting Identifying Permutation Binary Tree: Root at level (height) 0 Theorem: There exists some c > 0 such that for all algorithms which use comparisons to sort, and for all input sizes n, at least one input requires cn log n comparisons Fact: Binary tree of height h has at most 2 h leaves Observation from last slide: n! leaves needed comparison tree must have h log(n!) h is maximum (= worst-case) #comparisons needed to sort input of size n using the corresponding algorithm

45 Sorting Lower Bound (DETAIL) Goal: log(n!) (n log n) Claim: log(n!) O(n log n) n! n n log n! n log n Claim: log(n!) (n log n) n! (n/2) n/2 log n! n/2 log(n/2) 2 log n! n log (n/2) Observe: log (n/2) + 1 = log n 2 log (n/2) log n n > 2 4 log n! n 2 log (n/2) 4 log n! n log n

46 What About LB For the Average Case? Of possible interest: Worst-case analysis can be uninformative QuickSort: worst case is n 2 Simplex Method for linear programming: worst case is exponential Can we lower-bound average case complexity? First question: Is average case well-defined? Want i p i d i expected depth of a leaf in the comparison tree d i depth of leaf i; i = input with probability = p i Assume all input permutations equally probable ( equiprobable )

47 Average-Case Complexity of Sorting Q: Even though all sorting algs have some input which requires n log n time, is there an algorithm with better than (n log n) average-case performance? Theorem: If all n! input permutations equiprobable, then any decision tree that sorts has expected depth (n log n). Let D(m) smallest sum of leaf depths over all binary trees with m leaves Claim: D(m) m log m. If Claim true, use m = n! and fact that log n! (n log n) D(n!) n! log n! average leaf depth is (n log n)

48 Average-Case Complexity of Sorting (cont.) Claim: D(m) m log m Proof by induction on m. (D(T) sum of leaf depths of tree T, where unambiguous.) Claim trivial for m = 1; assume Claim m < k (strong I.H.). Any tree T with k leaves can be viewed as a root and two subtrees T i and T k-i (with i and k-i leaves respectively) D(T) = i + D(T i ) + (k-i) + D(T k-i ) D(k) = min 1 i k [k + D(i) + D(k-i)] k + min i [D(i) + D(k-i)] k + min i [i log i + (k-i) log (k-i)] (by I.H.) which is minimized for i = k/2. D(k) k + k log (k/2) = k + k(log k 1) = k log k

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 5: Divide and Conquer (Part 2) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ A Lower Bound on Convex Hull Lecture 4 Task: sort the

More information

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch]

Divide and Conquer. Andreas Klappenecker. [based on slides by Prof. Welch] Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch] Divide and Conquer Paradigm An important general technique for designing algorithms: divide problem into subproblems recursively

More information

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk CMPS 2200 Fall 2017 Divide-and-Conquer Carola Wenk Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk 1 The divide-and-conquer design paradigm 1. Divide the problem (instance)

More information

CPS 616 DIVIDE-AND-CONQUER 6-1

CPS 616 DIVIDE-AND-CONQUER 6-1 CPS 616 DIVIDE-AND-CONQUER 6-1 DIVIDE-AND-CONQUER Approach 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances recursively 3. Obtain solution to original (larger)

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;

More information

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count

Algorithms, Design and Analysis. Order of growth. Table 2.1. Big-oh. Asymptotic growth rate. Types of formulas for basic operation count Types of formulas for basic operation count Exact formula e.g., C(n) = n(n-1)/2 Algorithms, Design and Analysis Big-Oh analysis, Brute Force, Divide and conquer intro Formula indicating order of growth

More information

CSE 421 Algorithms: Divide and Conquer

CSE 421 Algorithms: Divide and Conquer CSE 42 Algorithms: Divide and Conquer Larry Ruzzo Thanks to Richard Anderson, Paul Beame, Kevin Wayne for some slides Outline: General Idea algorithm design paradigms: divide and conquer Review of Merge

More information

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101

A design paradigm. Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/ EECS 3101 A design paradigm Divide and conquer: (When) does decomposing a problem into smaller parts help? 09/09/17 112 Multiplying complex numbers (from Jeff Edmonds slides) INPUT: Two pairs of integers, (a,b),

More information

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences

CSE 421 Algorithms. T(n) = at(n/b) + n c. Closest Pair Problem. Divide and Conquer Algorithms. What you really need to know about recurrences CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer What you really need to know about recurrences Work per level changes geometrically with the level Geometrically increasing (x > 1) The

More information

Divide and Conquer. Andreas Klappenecker

Divide and Conquer. Andreas Klappenecker Divide and Conquer Andreas Klappenecker The Divide and Conquer Paradigm The divide and conquer paradigm is important general technique for designing algorithms. In general, it follows the steps: - divide

More information

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 14 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/ Lecture 14 Notes Goals for this week Big-O complexity

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms Spring 2017-2018 Outline 1 Sorting Algorithms (contd.) Outline Sorting Algorithms (contd.) 1 Sorting Algorithms (contd.) Analysis of Quicksort Time to sort array of length

More information

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

Lecture 1: Asymptotics, Recurrences, Elementary Sorting Lecture 1: Asymptotics, Recurrences, Elementary Sorting Instructor: Outline 1 Introduction to Asymptotic Analysis Rate of growth of functions Comparing and bounding functions: O, Θ, Ω Specifying running

More information

ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures ITEC2620 Introduction to Data Structures Lecture 6a Complexity Analysis Recursive Algorithms Complexity Analysis Determine how the processing time of an algorithm grows with input size What if the algorithm

More information

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis Lecture 15 Class URL: http://vlsicad.ucsd.edu/courses/cse21-s14/ Lecture 15 Notes Goals for this week Big-O complexity

More information

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 25 Pearson-Addison Wesley. All rights reserved. Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve

More information

Introduction to Algorithms 6.046J/18.401J/SMA5503

Introduction to Algorithms 6.046J/18.401J/SMA5503 Introduction to Algorithms 6.046J/8.40J/SMA5503 Lecture 3 Prof. Piotr Indyk The divide-and-conquer design paradigm. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving

More information

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 MA008 p.1/37 MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3 Dr. Markus Hagenbuchner markus@uow.edu.au. MA008 p.2/37 Exercise 1 (from LN 2) Asymptotic Notation When constants appear in exponents

More information

1 Divide and Conquer (September 3)

1 Divide and Conquer (September 3) The control of a large force is the same principle as the control of a few men: it is merely a question of dividing up their numbers. Sun Zi, The Art of War (c. 400 C.E.), translated by Lionel Giles (1910)

More information

Divide and Conquer. Recurrence Relations

Divide and Conquer. Recurrence Relations Divide and Conquer Recurrence Relations Divide-and-Conquer Strategy: Break up problem into parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. 2 MergeSort Mergesort.

More information

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14 Divide and Conquer Algorithms CSE 101: Design and Analysis of Algorithms Lecture 14 CSE 101: Design and analysis of algorithms Divide and conquer algorithms Reading: Sections 2.3 and 2.4 Homework 6 will

More information

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem CS 577 Introduction to Algorithms: Jin-Yi Cai University of Wisconsin Madison In the last class, we described InsertionSort and showed that its worst-case running time is Θ(n 2 ). Check Figure 2.2 for

More information

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 1 Tree definitions 1 2 Analysis of mergesort using a binary tree 1 3 Analysis of

More information

Divide-and-Conquer. a technique for designing algorithms

Divide-and-Conquer. a technique for designing algorithms Divide-and-Conquer a technique for designing algorithms decomposing instance to be solved into subinstances of the same problem solving each subinstance combining subsolutions to obtain the solution to

More information

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.

Chapter 5. Divide and Conquer CLRS 4.3. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Chapter 5 Divide and Conquer CLRS 4.3 Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve

More information

Divide and conquer. Philip II of Macedon

Divide and conquer. Philip II of Macedon Divide and conquer Philip II of Macedon Divide and conquer 1) Divide your problem into subproblems 2) Solve the subproblems recursively, that is, run the same algorithm on the subproblems (when the subproblems

More information

Divide-and-conquer: Order Statistics. Curs: Fall 2017

Divide-and-conquer: Order Statistics. Curs: Fall 2017 Divide-and-conquer: Order Statistics Curs: Fall 2017 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers.

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 http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d CS161, Lecture 4 Median, Selection, and the Substitution Method Scribe: Albert Chen and Juliana Cook (2015), Sam Kim (2016), Gregory Valiant (2017) Date: January 23, 2017 1 Introduction Last lecture, we

More information

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Partition and Select

Partition and Select Divide-Conquer-Glue Algorithms Quicksort, Quickselect and the Master Theorem Quickselect algorithm Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 11 Selection Problem: find the kth smallest number of an

More information

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016 CS125 Lecture 4 Fall 2016 Divide and Conquer We have seen one general paradigm for finding algorithms: the greedy approach. We now consider another general paradigm, known as divide and conquer. We have

More information

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015

CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 CMPT 307 : Divide-and-Conqer (Study Guide) Should be read in conjunction with the text June 2, 2015 1 Introduction The divide-and-conquer strategy is a general paradigm for algorithm design. This strategy

More information

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005

V. Adamchik 1. Recurrences. Victor Adamchik Fall of 2005 V. Adamchi Recurrences Victor Adamchi Fall of 00 Plan Multiple roots. More on multiple roots. Inhomogeneous equations 3. Divide-and-conquer recurrences In the previous lecture we have showed that if the

More information

Analysis of Algorithms - Using Asymptotic Bounds -

Analysis of Algorithms - Using Asymptotic Bounds - Analysis of Algorithms - Using Asymptotic Bounds - Andreas Ermedahl MRTC (Mälardalens Real-Time Research Center) andreas.ermedahl@mdh.se Autumn 004 Rehersal: Asymptotic bounds Gives running time bounds

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 1 Data Structures and Algorithms Chapter 3 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Review Of Topics. Review: Induction

Review Of Topics. Review: Induction Review Of Topics Asymptotic notation Solving recurrences Sorting algorithms Insertion sort Merge sort Heap sort Quick sort Counting sort Radix sort Medians/order statistics Randomized algorithm Worst-case

More information

Data selection. Lower complexity bound for sorting

Data selection. Lower complexity bound for sorting Data selection. Lower complexity bound for sorting Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 12 1 Data selection: Quickselect 2 Lower complexity bound for sorting 3 The

More information

Reductions, Recursion and Divide and Conquer

Reductions, Recursion and Divide and Conquer Chapter 5 Reductions, Recursion and Divide and Conquer CS 473: Fundamental Algorithms, Fall 2011 September 13, 2011 5.1 Reductions and Recursion 5.1.0.1 Reduction Reducing problem A to problem B: (A) Algorithm

More information

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example Recurrence Relations Chapter 2 Divide and Conquer Equation or an inequality that describes a function by its values on smaller inputs. Recurrence relations arise when we analyze the running time of iterative

More information

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: The maximum-subarray problem Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm: Brute force algorithm: At best, θ(n 2 ) time complexity 129 Can we do divide

More information

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline

CS 5321: Advanced Algorithms Analysis Using Recurrence. Acknowledgement. Outline CS 5321: Advanced Algorithms Analysis Using Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating

More information

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution.

! Break up problem into several parts. ! Solve each part recursively. ! Combine solutions to sub-problems into overall solution. Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer.! Break up problem into several parts.! Solve each part recursively.! Combine solutions to sub-problems into overall solution. Most common

More information

IS 709/809: Computational Methods in IS Research Fall Exam Review

IS 709/809: Computational Methods in IS Research Fall Exam Review IS 709/809: Computational Methods in IS Research Fall 2017 Exam Review Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Exam When: Tuesday (11/28) 7:10pm

More information

Divide and Conquer. Arash Rafiey. 27 October, 2016

Divide and Conquer. Arash Rafiey. 27 October, 2016 27 October, 2016 Divide the problem into a number of subproblems Divide the problem into a number of subproblems Conquer the subproblems by solving them recursively or if they are small, there must be

More information

Copyright 2000, Kevin Wayne 1

Copyright 2000, Kevin Wayne 1 Divide-and-Conquer Chapter 5 Divide and Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall solution. Most common

More information

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version)

CS 470/570 Divide-and-Conquer. Format of Divide-and-Conquer algorithms: Master Recurrence Theorem (simpler version) CS 470/570 Divide-and-Conquer Format of Divide-and-Conquer algorithms: Divide: Split the array or list into smaller pieces Conquer: Solve the same problem recursively on smaller pieces Combine: Build the

More information

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai Divide-and-Conquer Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, 33.4. CSE 6331 Algorithms Steve Lai Divide and Conquer Given an instance x of a prolem, the method works as follows: divide-and-conquer

More information

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science Divide & Conquer Jordi Cortadella and Jordi Petit Department of Computer Science Divide-and-conquer algorithms Strategy: Divide the problem into smaller subproblems of the same type of problem Solve the

More information

Outline. Part 5. Computa0onal Complexity (3) Compound Interest 2/15/12. Recurrence Rela0ons: An Overview. Recurrence Rela0ons: Formal Defini0on

Outline. Part 5. Computa0onal Complexity (3) Compound Interest 2/15/12. Recurrence Rela0ons: An Overview. Recurrence Rela0ons: Formal Defini0on Outline Part 5. Computa0onal Complexity (3) Recurrence Relations Divide and Conquer Understanding the Complexity of Algorithms CS 200 Algorithms and Data Structures 1 2 Recurrence Rela0ons: An Overview

More information

5. DIVIDE AND CONQUER I

5. DIVIDE AND CONQUER I 5. DIVIDE AND CONQUER I mergesort counting inversions closest pair of points median and selection Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos

More information

Week 5: Quicksort, Lower bound, Greedy

Week 5: Quicksort, Lower bound, Greedy Week 5: Quicksort, Lower bound, Greedy Agenda: Quicksort: Average case Lower bound for sorting Greedy method 1 Week 5: Quicksort Recall Quicksort: The ideas: Pick one key Compare to others: partition into

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Chapter 2 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: Room 5326, Engineering Building, Thursday 4:30pm -

More information

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science

Divide & Conquer. Jordi Cortadella and Jordi Petit Department of Computer Science Divide & Conquer Jordi Cortadella and Jordi Petit Department of Computer Science Divide-and-conquer algorithms Strategy: Divide the problem into smaller subproblems of the same type of problem Solve the

More information

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms

CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms CS 4407 Algorithms Lecture 3: Iterative and Divide and Conquer Algorithms Prof. Gregory Provan Department of Computer Science University College Cork 1 Lecture Outline CS 4407, Algorithms Growth Functions

More information

Divide and Conquer Strategy

Divide and Conquer Strategy Divide and Conquer Strategy Algorithm design is more an art, less so a science. There are a few useful strategies, but no guarantee to succeed. We will discuss: Divide and Conquer, Greedy, Dynamic Programming.

More information

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University

CS 5321: Advanced Algorithms - Recurrence. Acknowledgement. Outline. Ali Ebnenasir Department of Computer Science Michigan Technological University CS 5321: Advanced Algorithms - Recurrence Ali Ebnenasir Department of Computer Science Michigan Technological University Acknowledgement Eric Torng Moon Jung Chung Charles Ofria Outline Motivating example:

More information

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD Greedy s Greedy s Shortest path Claim 2: Let S be a subset of vertices containing s such that we know the shortest path length l(s, u) from s to any vertex in u S. Let e = (u, v) be an edge such that 1

More information

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n Class Note #14 Date: 03/01/2006 [Overall Information] In this class, we studied an algorithm for integer multiplication, which improved the running time from θ(n 2 ) to θ(n 1.59 ). We then used some of

More information

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort Xi Chen Columbia University We continue with two more asymptotic notation: o( ) and ω( ). Let f (n) and g(n) are functions that map

More information

Linear Time Selection

Linear Time Selection Linear Time Selection Given (x,y coordinates of N houses, where should you build road These lecture slides are adapted from CLRS.. Princeton University COS Theory of Algorithms Spring 0 Kevin Wayne Given

More information

CSCI 3110 Assignment 6 Solutions

CSCI 3110 Assignment 6 Solutions CSCI 3110 Assignment 6 Solutions December 5, 2012 2.4 (4 pts) Suppose you are choosing between the following three algorithms: 1. Algorithm A solves problems by dividing them into five subproblems of half

More information

Solving Recurrences. Lecture 23 CS2110 Fall 2011

Solving Recurrences. Lecture 23 CS2110 Fall 2011 Solving Recurrences Lecture 23 CS2110 Fall 2011 1 Announcements Makeup Prelim 2 Monday 11/21 7:30-9pm Upson 5130 Please do not discuss the prelim with your classmates! Quiz 4 next Tuesday in class Topics:

More information

data structures and algorithms lecture 2

data structures and algorithms lecture 2 data structures and algorithms 2018 09 06 lecture 2 recall: insertion sort Algorithm insertionsort(a, n): for j := 2 to n do key := A[j] i := j 1 while i 1 and A[i] > key do A[i + 1] := A[i] i := i 1 A[i

More information

Asymptotic Analysis and Recurrences

Asymptotic Analysis and Recurrences Appendix A Asymptotic Analysis and Recurrences A.1 Overview We discuss the notion of asymptotic analysis and introduce O, Ω, Θ, and o notation. We then turn to the topic of recurrences, discussing several

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms Introduction There exist many problems that can be solved using a divide-and-conquer algorithm. A divide-andconquer algorithm A follows these general guidelines. Divide Algorithm

More information

Data Structures and Algorithms CMPSC 465

Data Structures and Algorithms CMPSC 465 Data Structures and Algorithms CMPSC 465 LECTURE 9 Solving recurrences Substitution method Adam Smith S. Raskhodnikova and A. Smith; based on slides by E. Demaine and C. Leiserson Review question Draw

More information

Divide-Conquer-Glue Algorithms

Divide-Conquer-Glue Algorithms Divide-Conquer-Glue Algorithms Mergesort and Counting Inversions Tyler Moore CSE 3353, SMU, Dallas, TX Lecture 10 Divide-and-conquer. Divide up problem into several subproblems. Solve each subproblem recursively.

More information

Kartsuba s Algorithm and Linear Time Selection

Kartsuba s Algorithm and Linear Time Selection CS 374: Algorithms & Models of Computation, Fall 2015 Kartsuba s Algorithm and Linear Time Selection Lecture 09 September 22, 2015 Chandra & Manoj (UIUC) CS374 1 Fall 2015 1 / 32 Part I Fast Multiplication

More information

Data Structures and Algorithms Chapter 3

Data Structures and Algorithms Chapter 3 Data Structures and Algorithms Chapter 3 1. Divide and conquer 2. Merge sort, repeated substitutions 3. Tiling 4. Recurrences Recurrences Running times of algorithms with recursive calls can be described

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali February 19, 2013 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine

More information

CS 231: Algorithmic Problem Solving

CS 231: Algorithmic Problem Solving CS 231: Algorithmic Problem Solving Naomi Nishimura Module 4 Date of this version: June 11, 2018 WARNING: Drafts of slides are made available prior to lecture for your convenience. After lecture, slides

More information

Recurrence Relations

Recurrence Relations Recurrence Relations Winter 2017 Recurrence Relations Recurrence Relations A recurrence relation for the sequence {a n } is an equation that expresses a n in terms of one or more of the previous terms

More information

Asymptotic Algorithm Analysis & Sorting

Asymptotic Algorithm Analysis & Sorting Asymptotic Algorithm Analysis & Sorting (Version of 5th March 2010) (Based on original slides by John Hamer and Yves Deville) We can analyse an algorithm without needing to run it, and in so doing we can

More information

The Divide-and-Conquer Design Paradigm

The Divide-and-Conquer Design Paradigm CS473- Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm CS473 Lecture 4 1 The Divide-and-Conquer Design Paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems

More information

Algorithms and Data Structures

Algorithms and Data Structures Charles A. Wuethrich Bauhaus-University Weimar - CogVis/MMC June 1, 2017 1/44 Space reduction mechanisms Range searching Elementary Algorithms (2D) Raster Methods Shell sort Divide and conquer Quicksort

More information

Divide-Conquer-Glue. Divide-Conquer-Glue Algorithm Strategy. Skyline Problem as an Example of Divide-Conquer-Glue

Divide-Conquer-Glue. Divide-Conquer-Glue Algorithm Strategy. Skyline Problem as an Example of Divide-Conquer-Glue Divide-Conquer-Glue Tyler Moore CSE 3353, SMU, Dallas, TX February 19, 2013 Portions of these slides have been adapted from the slides written by Prof. Steven Skiena at SUNY Stony Brook, author of Algorithm

More information

Chapter 5 Divide and Conquer

Chapter 5 Divide and Conquer CMPT 705: Design and Analysis of Algorithms Spring 008 Chapter 5 Divide and Conquer Lecturer: Binay Bhattacharya Scribe: Chris Nell 5.1 Introduction Given a problem P with input size n, P (n), we define

More information

Divide-and-Conquer Algorithms and Recurrence Relations. Niloufar Shafiei

Divide-and-Conquer Algorithms and Recurrence Relations. Niloufar Shafiei Divide-and-Conquer Algorithms and Recurrence Relations Niloufar Shafiei Divide-and-conquer algorithms Divide-and-conquer algorithms: 1. Dividing the problem into smaller sub-problems 2. Solving those sub-problems

More information

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms )

CSE 613: Parallel Programming. Lectures ( Analyzing Divide-and-Conquer Algorithms ) CSE 613: Parallel Programming Lectures 13 14 ( Analyzing Divide-and-Conquer Algorithms ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Spring 2015 A Useful Recurrence Consider the

More information

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort

Sorting Algorithms. We have already seen: Selection-sort Insertion-sort Heap-sort. We will see: Bubble-sort Merge-sort Quick-sort Sorting Algorithms We have already seen: Selection-sort Insertion-sort Heap-sort We will see: Bubble-sort Merge-sort Quick-sort We will show that: O(n log n) is optimal for comparison based sorting. Bubble-Sort

More information

CS 2110: INDUCTION DISCUSSION TOPICS

CS 2110: INDUCTION DISCUSSION TOPICS CS 110: INDUCTION DISCUSSION TOPICS The following ideas are suggestions for how to handle your discussion classes. You can do as much or as little of this as you want. You can either present at the board,

More information

Fundamental Algorithms

Fundamental Algorithms Chapter 2: Sorting, Winter 2018/19 1 Fundamental Algorithms Chapter 2: Sorting Jan Křetínský Winter 2018/19 Chapter 2: Sorting, Winter 2018/19 2 Part I Simple Sorts Chapter 2: Sorting, Winter 2018/19 3

More information

Fundamental Algorithms

Fundamental Algorithms Fundamental Algorithms Chapter 2: Sorting Harald Räcke Winter 2015/16 Chapter 2: Sorting, Winter 2015/16 1 Part I Simple Sorts Chapter 2: Sorting, Winter 2015/16 2 The Sorting Problem Definition Sorting

More information

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt

What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency Asympt Lecture 3 The Analysis of Recursive Algorithm Efficiency What we have learned What is algorithm Why study algorithm The time and space efficiency of algorithm The analysis framework of time efficiency

More information

Divide and Conquer Algorithms

Divide and Conquer Algorithms Divide and Conquer Algorithms T. M. Murali March 17, 2014 Divide and Conquer Break up a problem into several parts. Solve each part recursively. Solve base cases by brute force. Efficiently combine solutions

More information

Computational Complexity - Pseudocode and Recursions

Computational Complexity - Pseudocode and Recursions Computational Complexity - Pseudocode and Recursions Nicholas Mainardi 1 Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it June 6, 2018 1 Partly Based on Alessandro

More information

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms. Solving recurrences Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms Example: Merge-Sort(A, p, r) 1: if p < r then 2: q (p + r)/2 3: Merge-Sort(A,

More information

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer.

CS 4104 Data and Algorithm Analysis. Recurrence Relations. Modeling Recursive Function Cost. Solving Recurrences. Clifford A. Shaffer. Department of Computer Science Virginia Tech Blacksburg, Virginia Copyright c 2010,2017 by Clifford A. Shaffer Data and Algorithm Analysis Title page Data and Algorithm Analysis Clifford A. Shaffer Spring

More information

Introduction to Divide and Conquer

Introduction to Divide and Conquer Introduction to Divide and Conquer Sorting with O(n log n) comparisons and integer multiplication faster than O(n 2 ) Periklis A. Papakonstantinou York University Consider a problem that admits a straightforward

More information

CSE 421, Spring 2017, W.L.Ruzzo. 8. Average-Case Analysis of Algorithms + Randomized Algorithms

CSE 421, Spring 2017, W.L.Ruzzo. 8. Average-Case Analysis of Algorithms + Randomized Algorithms CSE 421, Spring 2017, W.L.Ruzzo 8. Average-Case Analysis of Algorithms + Randomized Algorithms 1 outline and goals 1) Probability tools you've seen allow formal definition of "average case" running time

More information

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

Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Chapter 1 Divide and Conquer Polynomial Multiplication Algorithm Theory WS 2015/16 Fabian Kuhn Formulation of the D&C principle Divide-and-conquer method for solving a problem instance of size n: 1. Divide

More information

CS483 Design and Analysis of Algorithms

CS483 Design and Analysis of Algorithms CS483 Design and Analysis of Algorithms Lecture 6-8 Divide and Conquer Algorithms Instructor: Fei Li lifei@cs.gmu.edu with subject: CS483 Office hours: STII, Room 443, Friday 4:00pm - 6:00pm or by appointments

More information

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM

Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM Sorting Chapter 11-1 - Sorting Ø We have seen the advantage of sorted data representations for a number of applications q Sparse vectors q Maps q Dictionaries Ø Here we consider the problem of how to efficiently

More information

Integer Multiplication

Integer Multiplication Integer Multiplication in almost linear time Martin Fürer CSE 588 Department of Computer Science and Engineering Pennsylvania State University 1/24/08 Karatsuba algebraic Split each of the two factors

More information

Divide and Conquer CPE 349. Theresa Migler-VonDollen

Divide and Conquer CPE 349. Theresa Migler-VonDollen Divide and Conquer CPE 349 Theresa Migler-VonDollen Divide and Conquer Divide and Conquer is a strategy that solves a problem by: 1 Breaking the problem into subproblems that are themselves smaller instances

More information

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February) Algorithms and Data Structures 016 Week 5 solutions (Tues 9th - Fri 1th February) 1. Draw the decision tree (under the assumption of all-distinct inputs) Quicksort for n = 3. answer: (of course you should

More information

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information