Copyright 2000, Kevin Wayne 1
|
|
- Bernice Hunter
- 5 years ago
- Views:
Transcription
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 usage. Break up problem of size n into two equal parts of size ½n. Solve two parts recursively. Combine two solutions into overall solution in linear time. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. Consequence. Brute force: n 2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici. - Julius Caesar 2 3 Sorting 5.1 Mergesort Sorting. Given n elements, rearrange in ascending order. Obvious sorting applications. ist files in a directory. Organize a playlist. ist names in address book. Display Google PageRank results. Problems become easier once sorted. Find the median. Greedy algorithms. Find the closest pair. Binary search in a database. Identify statistical outliers. Find duplicates in a mailing list. Non-obvious sorting applications. Data compression. Computer graphics. Interval scheduling. Computational biology. Minimum spanning tree. Supply chain management. Simulate a system of particles. Book recommendations on Amazon. oad balancing on a parallel computer Copyright 2000, Kevin Wayne 1
2 Mergesort Merging Mergesort. Divide array into two halves. Recursively sort each half. Merge two halves to make sorted whole. Merging. Combine two pre-sorted lists into a sorted whole. How to merge efficiently? inear number of comparisons. Use temporary array. Jon von Neumann (1945) A G O R I T H M S A G O R H I M S T A G O R I T H M S divide O(1) A G H I A G O R H I M S T sort 2T(n/2) A G H I M O R S T merge O(n) Challenge for the bored. In-place merge. [Kronrud, 1969] using only a constant amount of extra storage 7 8 A Useful Recurrence Relation Proof by Telescoping Def. T(n) = number of comparisons to mergesort an input of size n. Claim. If T(n) satisfies this recurrence, then T(n) = n log 2 n. Mergesort recurrence. 0 if n =1 ) T(n) ( T( n/2 ) + T( % n/2& ) +!#" #!#" # % n otherwise ) * solve left half solve right half merging Solution. T(n) = O(n log 2 n). Pf. For n > 1: " 0 if n =1 T(n) = # 2T(n/2) + n!# "# % otherwise % sorting both halves merging T(n) n = = =! = 2T(n /2) n T(n /2) n/2 T(n / 4) n/4 T(n /n) n/n = log 2 n ! + 1 " # % log 2 n assumes n is a power of 2 9 Copyright 2000, Kevin Wayne 2
3 Proof by Induction Analysis of Mergesort Recurrence Claim. If T(n) satisfies this recurrence, then T(n) = n log 2 n. Claim. If T(n) satisfies the following recurrence, then T(n) n élg nù. " 0 if n =1 T(n) = # 2T(n/2) + n!# "# % otherwise % sorting both halves merging assumes n is a power of 2 T(n) 0 if n =1 ) ( T( n /2 ) + T( % n /2& ) +!#" #!#" # % n otherwise ) * solve left half solve right half merging log 2n Pf. (by induction on n) Base case: n = 1. Inductive hypothesis: T(n) = n log 2 n. Goal: show that T(2n) = 2n log 2 (2n). T(2n) = 2T(n) + 2n = 2nlog 2 n + 2n = 2n( log 2 (2n) 1) + 2n = 2nlog 2 (2n) Pf. (by induction on n) Base case: n = 1. Define n 1 = ën / 2û, n 2 = én / 2ù. Induction step: assume true for 1, 2,..., n 1. T(n) T(n 1 ) + T(n 2 ) + n n 1 # lgn 1 + n 2 # lg n 2 + n n 1 # lgn 2 + n 2 # lg n 2 + n = n # lgn 2 + n n( # lgn 1 ) + n = n# lgn n 2 = " n /2# " 2 " lg n # / 2 # = 2 " lg n # / 2 lgn 2 " lg n# Counting Inversions 5.3 Counting Inversions Music site tries to match your song preferences with others. You rank n songs. Music site consults database to find people with similar tastes. Similarity metric: number of inversions between two rankings. My rank: 1, 2,, n. Your rank: a 1, a 2,, a n. Songs i and j inverted if i < j, but a i > a j. Me You Songs A B C D E Inversions 3-2, 4-2 Brute force: check all Q(n 2 ) pairs i and j. 16 Copyright 2000, Kevin Wayne 3
4 Applications Counting Inversions: Divide-and-Conquer Applications. Voting theory. Collaborative filtering. Measuring the "sortedness" of an array. Genomic distance between two gene sequences. Sensitivity analysis of Googles ranking function. Rank aggregation for meta-searching on the Web. Nonparametric statistics (e.g., Kendalls Tau distance). Divide-and-conquer Counting Inversions: Divide-and-Conquer Counting Inversions: Divide-and-Conquer Divide-and-conquer. Divide: separate list into two pieces. Divide-and-conquer. Divide: separate list into two pieces. Conquer: recursively count inversions in each half. Divide: O(1). Divide: O(1). Conquer: 2T(n / 2) 5 blue-blue inversions 8 green-green inversions 5-4, 5-2, 4-2, 8-2, , 9-3, 9-7, -3, -7, -11, 11-3, Copyright 2000, Kevin Wayne 4
5 Counting Inversions: Divide-and-Conquer Counting Inversions: Combine Divide-and-conquer. Divide: separate list into two pieces. Conquer: recursively count inversions in each half. Combine: count inversions where a i and a j are in different halves, and return sum of three quantities. Combine: count blue-green inversions Assume each half is sorted. Count inversions where a i and a j are in different halves. Merge two sorted halves into sorted whole. to maintain sorted invariant Divide: O(1) Conquer: 2T(n / 2) 13 blue-green inversions: Count: O(n) 5 blue-blue inversions 8 green-green inversions 9 blue-green inversions 5-3, 4-3, 8-6, 8-3, 8-7, 10-6, 10-9, 10-3, 10-7 Combine:??? Merge: O(n) Total = = 22. T(n) T( # n/2 ) + T( % n/2& ) + O(n) T(n) = O(nlog n) 22 Counting Inversions: Implementation Pre-condition. [Merge-and-Count] A and B are sorted. Post-condition. [Sort-and-Count] is sorted. 5.4 Sort-and-Count() { if list has one element return 0 and the list Divide the list into two halves A and B (r A, A) Sort-and-Count(A) (r B, B) Sort-and-Count(B) (r B, ) Merge-and-Count(A, B) } return r = r A + r B + r and the sorted list 23 Copyright 2000, Kevin Wayne 5
6 : First Attempt Closest pair. Given n points in the plane, find a pair with smallest Euclidean distance between them. Divide. Sub-divide region into 4 quadrants. Fundamental geometric primitive. Graphics, computer vision, geographic information systems, molecular modeling, air traffic control. Special case of nearest neighbor, Euclidean MST, Voronoi. fast closest pair inspired fast algorithms for these problems Brute force. Check all pairs of points p and q with Q(n 2 ) comparisons. 1-D version. O(n log n) easy if points are on a line. Assumption. No two points have same x coordinate. to make presentation cleaner : First Attempt Divide. Sub-divide region into 4 quadrants. Obstacle. Impossible to ensure n/4 points in each piece. Algorithm. Divide: draw vertical line so that roughly ½n points on each side Copyright 2000, Kevin Wayne 6
7 Algorithm. Divide: draw vertical line so that roughly ½n points on each side. Conquer: find closest pair in each side recursively. Algorithm. Divide: draw vertical line so that roughly ½n points on each side. Conquer: find closest pair in each side recursively. Combine: find closest pair with one point in each side. Return best of 3 solutions. seems like Q(n 2 ) Find closest pair with one point in each side, assuming that distance < d. Find closest pair with one point in each side, assuming that distance < d. Observation: only need to consider points within d of line. d = min(, ) d = min(, ) 31 d 32 Copyright 2000, Kevin Wayne 7
8 Find closest pair with one point in each side, assuming that distance < d. Observation: only need to consider points within d of line. Sort points in 2d-strip by their y coordinate. Find closest pair with one point in each side, assuming that distance < d. Observation: only need to consider points within d of line. Sort points in 2d-strip by their y coordinate. Only check distances of those within 11 positions in sorted list! d = min(, ) 3 d = min(, ) d 33 d 34 Closest Pair Algorithm Def. et s i be the point in the 2d-strip, with the i th smallest y-coordinate. Claim. If i j ³, then the distance between s i and s j is at least d. Pf. No two points lie in same ½d-by-½d box. Two points at least 2 rows apart have distance ³ 2(½d). 2 rows j ½d ½d Closest-Pair(p 1,, p n ) { Compute separation line such that half the points are on one side and half on the other side. d 1 = Closest-Pair(left half) d 2 = Closest-Pair(right half) d = min(d 1, d 2 ) Delete all points further than d from separation line Sort remaining points by y-coordinate. O(n log n) 2T(n / 2) O(n) O(n log n) Fact. Still true if we replace with 7. i ½d Scan points in y-order and compare distance between each point and next 11 neighbors. If any of these distances is less than d, update d. O(n) } return d. d d Copyright 2000, Kevin Wayne 8
9 : Analysis Running time. 5.5 Integer Multiplication T(n) 2T( n/2) + O(n log n) T(n) = O(n log 2 n) Q. Can we achieve O(n log n)? A. Yes. Dont sort points in strip from scratch each time. Each recursive returns two lists: all points sorted by y coordinate, and all points sorted by x coordinate. Sort by merging two pre-sorted lists. T(n) 2T( n/2) + O(n) T(n) = O(n log n) 37 Integer Arithmetic Divide-and-Conquer Multiplication: Warmup Add. Given two n-digit integers a and b, compute a + b. O(n) bit operations. Multiply. Given two n-digit integers a and b, compute a b. Brute force solution: Q(n 2 ) bit operations. * Multiply Add To multiply two n-digit integers: Multiply four ½n-digit integers. Add two ½n-digit integers, and shift to obtain result. x = 2 n /2 x 1 + x 0 y = 2 n /2 y 1 + y 0 ( ) ( 2 n /2 y 1 + y 0 ) = 2 n x 1 y n /2 x 1 y 0 + x 0 y 1 xy = 2 n /2 x 1 + x 0 T(n) = 4T( n/2 )!# "# +! Θ(n) " T(n) = Θ(n2 ) recursive calls add, shift assumes n is a power of 2 ( ) + x 0 y Copyright 2000, Kevin Wayne 9
10 Karatsuba Multiplication Karatsuba: Recursion Tree To multiply two n-digit integers: Add two ½n digit integers. Multiply three ½n-digit integers. Add, subtract, and shift ½n-digit integers to obtain result. " 0 if n =1 T(n) = # 3T(n/2) + n otherwise T(n) log 2 n ( ) k T(n) = n 2 3 = k=0 ( ) 1+log 2 n = 3n log n x = 2 n /2 x 1 + x 0 y = 2 n /2 y 1 + y 0 xy = 2 n x 1 y n /2 ( x 1 y 0 + x 0 y 1 ) + x 0 y 0 T(n/2) T(n/2) T(n/2) 3(n/2) = 2 n x 1 y n /2 ( (x 1 + x 0 )(y 1 + y 0 ) x 1 y 1 x 0 y 0 ) + x 0 y 0 A B A C C Theorem. [Karatsuba-Ofman, 1962] Can multiply two n-digit integers in O(n ) bit operations.... 9(n/4)... ( ) + T( n /2 ) + T( 1+ n /2 ) T(n) T n /2 % & % &!####### "####### recursive calls + Θ(n)!# "# add, subtract, shift T(n / 2 k )... 3 k (n / 2 k )... T(n) = O(n log 2 3 ) = O(n ) T(2) T(2) T(2) T(2) T(2) T(2) T(2) T(2) 3 lg n (2) Matrix Multiplication Matrix Multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. n c ij = a ik b kj k=1 " c c! c % 11 1n c c 22! c 2n " " # " # c n1 c n2! c nn & = " a a! a % 11 1n a a 22! a 2n " " # " # a n1 a n2! a nn & " b b! b % 11 1n b b 22! b 2n " " # " # b n1 b n2! b nn & Brute force. Q(n 3 ) arithmetic operations. Fundamental question. Can we improve upon brute force? 44 Copyright 2000, Kevin Wayne 10
11 Matrix Multiplication: Warmup Matrix Multiplication: Key Idea Divide-and-conquer. Divide: partition A and B into ½n-by-½n blocks. Conquer: multiply 8 ½n-by-½n recursively. Combine: add appropriate products using 4 matrix additions. Key idea. multiply 2-by-2 block matrices with only 7 multiplications. " C 11 C % " A = 11 A % " B 11 B % P 1 = A 11 (B B 22 ) # C C 22 & # A A 22 & # B B 22 & P 2 = ( A 11 + A ) B 22 " C 11 C % " = A 11 A % " B 11 B % # C C 22 & # A A 22 & # B B 22 & C 11 = ( A 11 B 11 ) + ( A B ) C = ( A 11 B ) + ( A B 22 ) C = ( A B 11 ) + ( A 22 B ) C 22 = ( A B ) + ( A 22 B 22 ) C 11 = P 5 + P 4 P 2 + P 6 C = P 1 + P 2 C = P 3 + P 4 C 22 = P 5 + P 1 P 3 P 7 P 3 = ( A + A 22 ) B 11 P 4 = A 22 (B B 11 ) P 5 = ( A 11 + A 22 ) (B 11 + B 22 ) P 6 = ( A A 22 ) (B + B 22 ) P 7 = ( A 11 A ) (B 11 + B ) T(n) = 8T( n/2 )!# "# + Θ(n2 )!##" ## recursive calls add, form submatrices T(n) = Θ(n 3 ) 7 multiplications. 18 = additions (or subtractions) Fast Matrix Multiplication Fast Matrix Multiplication in Practice Fast matrix multiplication. (Strassen, 1969) Divide: partition A and B into ½n-by-½n blocks. Compute: 14 ½n-by-½n matrices via 10 matrix additions. Conquer: multiply 7 ½n-by-½n matrices recursively. Combine: 7 products into 4 terms using 8 matrix additions. Analysis. Assume n is a power of 2. T(n) = # arithmetic operations. T(n) = 7T( n/2 )!# "# + Θ(n2 ) T(n) = Θ(n log 2 7 ) = O(n 2.81 )!#" # recursive calls add, subtract Implementation issues. Sparsity. Caching effects. Numerical stability. Odd matrix dimensions. Crossover to classical algorithm around n = 8. Common misperception: "Strassen is only a theoretical curiosity." Advanced Computation Group at Apple Computer reports 8x speedup on G4 Velocity Engine when n ~ 2,500. Range of instances where its useful is a subject of controversy. Remark. Can "Strassenize" Ax=b, determinant, eigenvalues, and other matrix ops Copyright 2000, Kevin Wayne 11
12 Fast Matrix Multiplication in Theory Fast Matrix Multiplication in Theory Q. Multiply two 2-by-2 matrices with only 7 scalar multiplications? A. Yes! [Strassen, 1969] Θ(n log 2 7 ) = O(n 2.81 ) Q. Multiply two 2-by-2 matrices with only 6 scalar multiplications? A. Impossible. [Hopcroft and Kerr, 1971] Θ(n log 2 6 ) = O(n 2.59 ) Q. Two 3-by-3 matrices with only scalar multiplications? A. Also impossible. Θ(n log 3 ) = O(n 2.77 ) Best known. O(n ) [Francois e Gall, 2014] Conjecture. O(n 2+e ) for any e > 0. Caveat. Theoretical improvements to Strassen are progressively less practical. The constant coefficient hidden by the Big O notation is so large that these algorithms are only worthwhile for matrices that are too large to handle on present-day computers. Q. Two 70-by-70 matrices with only 143,640 scalar multiplications? A. Yes! [Pan, 1980] Θ(n log ) = O(n 2.80 ) Decimal wars. December, 1979: O(n ). January, 1980: O(n ) Copyright 2000, Kevin Wayne
! 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 informationDivide-and-Conquer. Consequence. Brute force: n 2. Divide-and-conquer: n log n. Divide et impera. Veni, vidi, vici.
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 usage. Break up problem of
More informationChapter 5. Divide and Conquer. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 5 Divide and Conquer 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 each
More informationChapter 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 informationChapter 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 information5. 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 information5. 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 informationMatrix Multiplication
Matrix Multiplication Matrix Multiplication Matrix multiplication. Given two n-by-n matrices A and B, compute C = AB. n c ij = a ik b kj k=1 c 11 c 12 c 1n c 21 c 22 c 2n c n1 c n2 c nn = a 11 a 12 a 1n
More informationAlgorithm 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 informationDivide-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 informationChapter 5. Divide and Conquer. CS 350 Winter 2018
Chapter 5 Divide and Conquer CS 350 Winter 2018 1 Divide-and-Conquer Divide-and-conquer. Break up problem into several parts. Solve each part recursively. Combine solutions to sub-problems into overall
More informationCSE 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 information5. DIVIDE AND CONQUER I
5. DIVIDE AND CONQUER I mergesort counting inversions randomized quicksort median and selection closest pair of points Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos
More informationHow to Multiply. 5.5 Integer Multiplication. Complex Multiplication. Integer Arithmetic. Complex multiplication. (a + bi) (c + di) = x + yi.
How to ultiply Slides by Kevin Wayne. Copyright 5 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials Complex ultiplication Complex multiplication. a + bi) c + di) = x + yi.
More informationDivide-and-conquer. Curs 2015
Divide-and-conquer Curs 2015 The divide-and-conquer strategy. 1. Break the problem into smaller subproblems, 2. recursively solve each problem, 3. appropriately combine their answers. Known Examples: Binary
More informationDivide-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 informationCopyright 2000, Kevin Wayne 1
//8 Fast Integer Division Too (!) Schönhage Strassen algorithm CS 8: Algorithm Design and Analysis Integer division. Given two n-bit (or less) integers s and t, compute quotient q = s / t and remainder
More informationCPS 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 informationCS 580: Algorithm Design and Analysis
CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 208 Announcement: Homework 3 due February 5 th at :59PM Final Exam (Tentative): Thursday, May 3 @ 8AM (PHYS 203) Recap: Divide
More informationDIVIDE AND CONQUER II
DIVIDE AND CONQUER II master theorem integer multiplication matrix multiplication convolution and FFT Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos
More informationDivide 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 informationDivide 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 informationLinear 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 informationDesign and Analysis of Algorithms
CSE 101, Winter 2018 Design and Analysis of Algorithms Lecture 4: Divide and Conquer (I) Class URL: http://vlsicad.ucsd.edu/courses/cse101-w18/ Divide and Conquer ( DQ ) First paradigm or framework DQ(S)
More informationCS 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 information1. Basic Algorithms: Bubble Sort
Sorting Algorithms Sorting Sorting. Given n elements, rearrange in ascending order. Obvious sorting applications. List files in a directory. Organize an MP3 library. List names in a phone book. Display
More informationCS483 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 informationLecture 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 informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright Pearson-Addison Wesley. All rights reserved. 4 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and finishes
More informationAlgorithms, 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 information1. Basic Algorithms: Bubble Sort
Sorting Algorithms Sorting Sorting. Given n elements, rearrange in ascending order. Obvious sorting applications. List files in a directory. Organize an MP3 library. List names in a phone book. Display
More informationCMPSCI611: Three Divide-and-Conquer Examples Lecture 2
CMPSCI611: Three Divide-and-Conquer Examples Lecture 2 Last lecture we presented and analyzed Mergesort, a simple divide-and-conquer algorithm. We then stated and proved the Master Theorem, which gives
More informationCSC373: Algorithm Design, Analysis and Complexity Fall 2017
CSC373: Algorithm Design, Analysis and Complexity Fall 2017 Allan Borodin (in collaboration with Rabia Bakhteri and with occasional guest lectures by Nisarg Shah and Denis Pankratov) September 13, 2017
More informationDivide 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 informationA 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 informationMatching Residents to Hospitals
Midterm Review Matching Residents to Hospitals Goal. Given a set of preferences among hospitals and medical school students, design a self-reinforcing admissions process. Unstable pair: applicant x and
More informationDivide 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 informationThe 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 informationIntroduction 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 informationReductions, 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 informationObjec&ves. Review. Divide and conquer algorithms
Objec&ves Divide and conquer algorithms Ø Recurrence rela&ons Ø Coun&ng inversions March 9, 2018 CSCI211 - Sprenkle 1 Review What approach are we learning to solve problems (as of Wednesday)? What is a
More informationDivide 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 informationUniversity of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers. Lecture 5
University of the Virgin Islands, St. Thomas January 14, 2015 Algorithms and Programming for High Schoolers Numerical algorithms: Lecture 5 Today we ll cover algorithms for various numerical problems:
More informationDivide 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 informationDivide & 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 informationDivide & Conquer. CS 320, Fall Dr. Geri Georg, Instructor CS320 Div&Conq 1
Divide & Conquer CS 320, Fall 2017 Dr. Geri Georg, Instructor georg@colostate.edu CS320 Div&Conq 1 Strategy 1. Divide the problem up into equal sized sub problems 2. Solve the sub problems recursively
More informationDivide 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 informationKartsuba 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 informationCOMP 355 Advanced Algorithms
COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Running Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that
More information2. ALGORITHM ANALYSIS
2. ALGORITHM ANALYSIS computational tractability asymptotic order of growth survey of common running times Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos
More informationDivide 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/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17
601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17 2.1 Notes Homework 1 will be released today, and is due a week from today by the beginning
More informationCSE 202 Dynamic Programming II
CSE 202 Dynamic Programming II Chapter 6 Dynamic Programming Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 Algorithmic Paradigms Greed. Build up a solution incrementally,
More informationCOMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background
COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background 1 Polynomial Time Brute force. For many non-trivial problems, there is a natural brute force search algorithm that checks every
More informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and
More informationAsymptotic 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 informationCS483 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 informationChapter 4 Divide-and-Conquer
Chapter 4 Divide-and-Conquer 1 About this lecture (1) Recall the divide-and-conquer paradigm, which we used for merge sort: Divide the problem into a number of subproblems that are smaller instances of
More informationDivide-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 informationCSE 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 informationCOMP 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 informationDivide 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 informationb + 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 informationLecture 2: Divide and conquer and Dynamic programming
Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in
More informationCopyright 2000, Kevin Wayne 1
Chapter 2 2.1 Computational Tractability Basics of Algorithm Analysis "For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious.
More informationCopyright 2000, Kevin Wayne 1
Algorithm runtime analysis and computational tractability Time Complexity of an Algorithm How do we measure the complexity (time, space requirements) of an algorithm. 1 microsecond? Units of time As soon
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication
CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication Integer multiplication Say we have 5 baskets with 8 apples in each How do we determine how many apples we have? Count them all? That would take
More informationDivide 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 information2.1 Computational Tractability. Chapter 2. Basics of Algorithm Analysis. Computational Tractability. Polynomial-Time
Chapter 2 2.1 Computational Tractability Basics of Algorithm Analysis "For me, great algorithms are the poetry of computation. Just like verse, they can be terse, allusive, dense, and even mysterious.
More informationCS 580: Algorithm Design and Analysis
CS 580: Algorithm Design and Analysis Jeremiah Blocki Purdue University Spring 2018 Reminder: Homework 1 due tonight at 11:59PM! Recap: Greedy Algorithms Interval Scheduling Goal: Maximize number of meeting
More informationAlgorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE
Algorithms ROBERT SEDGEWICK KEVIN WAYNE 2.2 MERGESORT Algorithms F O U R T H E D I T I O N mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE http://algs4.cs.princeton.edu
More informationCMPS 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 informationThe 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 informationAlgorithms And Programming I. Lecture 5 Quicksort
Algorithms And Programming I Lecture 5 Quicksort Quick Sort Partition set into two using randomly chosen pivot 88 31 25 52 14 98 62 30 23 79 14 31 2530 23 52 88 62 98 79 Quick Sort 14 31 2530 23 52 88
More informationAnalysis 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 informationData 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 informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.1 Interval Scheduling Interval Scheduling Interval scheduling. Job j starts at s j and
More information6. DYNAMIC PROGRAMMING I
6. DYNAMIC PROGRAMMING I weighted interval scheduling segmented least squares knapsack problem RNA secondary structure Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley Copyright 2013
More informationClass 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 informationCSE101: 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 information1 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 informationLecture 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 informationAlgorithms Design & Analysis. Analysis of Algorithm
Algorithms Design & Analysis Analysis of Algorithm Review Internship Stable Matching Algorithm 2 Outline Time complexity Computation model Asymptotic notions Recurrence Master theorem 3 The problem of
More informationThe PRIMES 2014 problem set
Dear PRIMES applicant! The PRIMES 24 problem set This is the PRIMES 24 problem set. Please send us your solutions as part of your PRIMES application by December, 24. For complete rules, see http://web.mit.edu/primes/apply.shtml
More informationChapter 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 informationDivide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201
Divide and Conquer: Polynomial Multiplication Version of October 7, 2014 Divide and Conquer: Polynomial Multiplication Version of October 1 / 7, 24201 Outline Outline: Introduction The polynomial multiplication
More informationFall 2017 November 10, Written Homework 5
CS1800 Discrete Structures Profs. Aslam, Gold, & Pavlu Fall 2017 November 10, 2017 Assigned: Mon Nov 13 2017 Due: Wed Nov 29 2017 Instructions: Written Homework 5 The assignment has to be uploaded to blackboard
More informationDiscrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion
Discrete Mathematics U. Waterloo ECE 103, Spring 2010 Ashwin Nayak May 17, 2010 Recursion During the past week, we learnt about inductive reasoning, in which we broke down a problem of size n, into one
More informationDivide and Conquer Problem Solving Method
Divide and Conquer Problem Solving Method 1. Problem Instances Let P be a problem that is amenable to the divide and conquer algorithm design method and let P 0, P 1, P 2, be distinct instances of the
More informationDesign and Analysis of Algorithms
Design and Analysis of Algorithms CSE 5311 Lecture 5 Divide and Conquer: Fast Fourier Transform Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms
More informationChapter 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 informationIntroduction 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 informationDivide-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 informationCS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya
CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Matrix multiplication September 14, 2005 L2.27 Standard algorithm for i 1 to n do for j 1 ton do c ij 0 for k 1 to
More informationWeek 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 informationLecture 4. Quicksort
Lecture 4. Quicksort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright 2000-2018 Networking
More informationshelat divide&conquer closest points matrixmult median
L6feb 9 2016 shelat 4102 divide&conquer closest points matrixmult median 7.5 7.8 9.5 3.7 26.1 closest pair of points simple brute force approach takes 14 1 2 7 8 9 4 13 3 10 11 5 12 6 solve the large problem
More informationSelection and Adversary Arguments. COMP 215 Lecture 19
Selection and Adversary Arguments COMP 215 Lecture 19 Selection Problems We want to find the k'th largest entry in an unsorted array. Could be the largest, smallest, median, etc. Ideas for an n lg n algorithm?
More informationDesign 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 informationQuicksort algorithm Average case analysis
Quicksort algorithm Average case analysis After today, you should be able to implement quicksort derive the average case runtime of quick sort and similar algorithms Q1-3 For any recurrence relation in
More information