Similar idea to multiplication in N, C. Divide and conquer approach provides unexpected improvements. Naïve matrix multiplication

Similar documents
This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

5. Solving recurrences

Algorithms and Data Structures Lecture IV

Merge Sort. Outline and Reading. Divide-and-Conquer. Divide-and-conquer paradigm ( 4.1.1) Merge-sort ( 4.1.1)

Lecture 4 Recursive Algorithm Analysis. Merge Sort Solving Recurrences The Master Theorem

Lecture 4 Recursive Algorithm Analysis. Merge Sort Solving Recurrences The Master Theorem

Section IV.6: The Master Method and Applications

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Divide-and-Conquer


( a n ) converges or diverges.

Numbers (Part I) -- Solutions

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

Data Structures and Algorithm. Xiaoqing Zheng

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Section 6.3: Geometric Sequences

CS 331 Design and Analysis of Algorithms. -- Divide and Conquer. Dr. Daisy Tang

M3P14 EXAMPLE SHEET 1 SOLUTIONS

1.3 Continuous Functions and Riemann Sums

Data Structures Lecture 9

Divide-and-Conquer. Divide-and-Conquer 1

PROGRESSIONS AND SERIES

Data Structures and Algorithms CMPSC 465

Relation of BSTs to Quicksort, Analysis of Random BST. Lecture 9

CS 332: Algorithms. Quicksort

Taylor Polynomials. The Tangent Line. (a, f (a)) and has the same slope as the curve y = f (x) at that point. It is the best

Week 13 Notes: 1) Riemann Sum. Aim: Compute Area Under a Graph. Suppose we want to find out the area of a graph, like the one on the right:

SM2H. Unit 2 Polynomials, Exponents, Radicals & Complex Numbers Notes. 3.1 Number Theory

Lesson-2 PROGRESSIONS AND SERIES

Introduction to Algorithms 6.046J/18.401J

Chapter 5. The Riemann Integral. 5.1 The Riemann integral Partitions and lower and upper integrals. Note: 1.5 lectures

) 2 2(2. Assume that

Model of Computation and Runtime Analysis

1. (25 points) Use the limit definition of the definite integral and the sum formulas to compute. [1 x + x2

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

Fig. 1. I a. V ag I c. I n. V cg. Z n Z Y. I b. V bg

Algorithm Design and Analysis

Math 3B Midterm Review

Model of Computation and Runtime Analysis

Analysis of Algorithms -Quicksort-

We will begin by supplying the proof to (a).

Data Structures and Algorithms

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Design and Analysis of Algorithms

THE NATIONAL UNIVERSITY OF IRELAND, CORK COLÁISTE NA hollscoile, CORCAIGH UNIVERSITY COLLEGE, CORK SUMMER EXAMINATION 2005 FIRST ENGINEERING

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro

Fundamental Algorithms

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

CS473-Algorithms I. Lecture 3. Solving Recurrences. Cevdet Aykanat - Bilkent University Computer Engineering Department

lecture 16: Introduction to Least Squares Approximation

b a 2 ((g(x))2 (f(x)) 2 dx

MTH 146 Class 16 Notes

FOURIER SERIES PART I: DEFINITIONS AND EXAMPLES. To a 2π-periodic function f(x) we will associate a trigonometric series. a n cos(nx) + b n sin(nx),

Review of the Riemann Integral

UNIVERSITY OF BRISTOL. Examination for the Degrees of B.Sc. and M.Sci. (Level C/4) ANALYSIS 1B, SOLUTIONS MATH (Paper Code MATH-10006)

POWER SERIES R. E. SHOWALTER

MATH 118 HW 7 KELLY DOUGAN, ANDREW KOMAR, MARIA SIMBIRSKY, BRANDEN LASKE

4.3 Growth Rates of Solutions to Recurrences

,... are the terms of the sequence. If the domain consists of the first n positive integers only, the sequence is a finite sequence.

0 otherwise. sin( nx)sin( kx) 0 otherwise. cos( nx) sin( kx) dx 0 for all integers n, k.

Chapter 7 Infinite Series

Fast Fourier Transform 1) Legendre s Interpolation 2) Vandermonde Matrix 3) Roots of Unity 4) Polynomial Evaluation

Unit 1. Extending the Number System. 2 Jordan School District

A GENERAL METHOD FOR SOLVING ORDINARY DIFFERENTIAL EQUATIONS: THE FROBENIUS (OR SERIES) METHOD

MAS221 Analysis, Semester 2 Exercises

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

Improving XOR-Dominated Circuits by Exploiting Dependencies between Operands. Ajay K. Verma and Paolo Ienne. csda

EVALUATING DEFINITE INTEGRALS

Graphing Review Part 3: Polynomials

 n. A Very Interesting Example + + = d. + x3. + 5x4. math 131 power series, part ii 7. One of the first power series we examined was. 2!

Test Info. Test may change slightly.

LEVEL I. ,... if it is known that a 1

Advanced Algorithmic Problem Solving Le 6 Math and Search

Discrete Mathematics I Tutorial 12

SUTCLIFFE S NOTES: CALCULUS 2 SWOKOWSKI S CHAPTER 11

SUTCLIFFE S NOTES: CALCULUS 2 SWOKOWSKI S CHAPTER 11

Algorithms Design & Analysis. Divide & Conquer

INTEGRATION IN THEORY

General properties of definite integrals

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

The total number of permutations of S is n!. We denote the set of all permutations of S by

Chapter Real Numbers

z line a) Draw the single phase equivalent circuit. b) Calculate I BC.

MA123, Chapter 9: Computing some integrals (pp )

Section 11.5 Notes Page Partial Fraction Decomposition. . You will get: +. Therefore we come to the following: x x

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

The limit comparison test

Statistics for Financial Engineering Session 1: Linear Algebra Review March 18 th, 2006

Surds, Indices, and Logarithms Radical

Student Success Center Elementary Algebra Study Guide for the ACCUPLACER (CPT)

Sect Simplifying Radical Expressions. We can use our properties of exponents to establish two properties of radicals: and

Chapter 2 Infinite Series Page 1 of 9

is an ordered list of numbers. Each number in a sequence is a term of a sequence. n-1 term

f(bx) dx = f dx = dx l dx f(0) log b x a + l log b a 2ɛ log b a.

INTEGRATION TECHNIQUES (TRIG, LOG, EXP FUNCTIONS)

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

10.5 Test Info. Test may change slightly.

EXERCISE a a a 5. + a 15 NEETIIT.COM

Math 104: Final exam solutions

Northwest High School s Algebra 2

Transcription:

Next. Covered bsics of simple desig techique (Divided-coquer) Ch. of the text.. Next, Strsse s lgorithm. Lter: more desig d coquer lgorithms: MergeSort. Solvig recurreces d the Mster Theorem. Similr ide to multiplictio i N, C Divide d coquer pproch provides uexpected improvemets 5/5/00 CSE 0 Lecture Nïve mtrix multiplictio SimpleMtrixMultiply (A,B). N A.rows. C CreteMtrix(,). for i to 4. for j to 5. C[i,j] 0 6. for k to 7. C[i,j] C[i,j] + A[i,k]*B[k,j] 8. retur C Argue tht the ruig time is θ( ) First ttempt d Divide & Coquer Divide A,B ito 4 / x / mtrices C A B + A B C A B + A B C A B + A B C A B + A B Simple Recursive implemettio. Ruig time is give by the followig recurrece. T() C, d for > T() 8T(/) + θ( ) θ( ) time-complexity Strsse s lgorithm Avoid oe multiplictio (detils o pge 80) (but uses more dditios) Recurrece: T() C, d for > T() 7T(/) + θ( ) How c we solve this? Will see tht T() θ( lg 7 ), lg 7.807. The mximum-subrry problem Give rry of itegers, fid cotiguous subrry with the mximum sum. Very ïve lgorithm: Brute force lgorithm: At best, θ( ) time complexity

C we do divide d coquer? Wt to use swers from left d right hlf subrrys. Problem: The swer my ot lie i either! Key questio: Wht iformtio do we eed from (smller) subproblems to solve the big problem? A divide d coquer lgorithm Algorithm i Ch 4.: Recurrece: T() C, d for > T() T(/) + θ() Relted questio: how do we get this iformtio? T() θ( log ) More divide d coquer : Merge Sort Divide: If S hs t lest two elemets (othig eeds to be doe if S hs zero or oe elemets), remove ll the elemets from S d put them ito two sequeces, S d S, ech cotiig bout hlf of the elemets of S. (i.e. S cotis the first / elemets d S cotis the remiig / elemets). Coquer: Sort sequeces S d S usig Merge Sort. Combie: Put bck the elemets ito S by mergig the sorted sequeces S d S ito oe sorted sequece Merge Sort: Algorithm Merge-Sort(A, p, p, r) r) if if p < r the the q (p+r)/ Merge-Sort(A, p, p, q) q) Merge-Sort(A, q+, q+, r) r) Merge(A, p, p, q, q, r) r) Merge(A, p, p, q, q, r) r) Tke Tke the the smllest of of the the two two topmost elemets of of sequeces A[p..q] d d A[q+..r] d d put put ito ito the the resultig sequece. Repet this, this, util util both both sequeces re re empty. Copy Copy the the resultig sequece ito ito A[p..r].

Merge Sort: summry To sort umbers if doe! recursively sort lists of umbers / d / elemets merge sorted lists i Θ() time Strtegy brek problem ito similr (smller) subproblems recursively solve subproblems combie solutios to swer Recurreces Ruig times of lgorithms with Recursive clls c be described usig recurreces A recurrece is equtio or iequlity tht describes fuctio i terms of its vlue o smller iputs Exmple: Merge Sort solvig_trivil_problem if T ( ) um_pieces T ( / subproblem_size_fctor) + dividig + combiig if > Θ () if T ( ) T ( /) +Θ ( ) if > Solvig recurreces Repeted substitutio method Expdig the recurrece by substitutio d oticig ptters Substitutio method guessig the solutios verifyig the solutio by the mthemticl iductio Recursio-trees Mster method templtes for differet clsses of recurreces Repeted Substitutio Method Let s fid the ruig time of merge sort (let s ssume tht b, for some b). if T( ) T( /) + if > T( ) T( / ) + substitute ( T( /4 ) + / ) + expd T( / 4) + substitute ( T( /8) + / 4) + expd T( /8) + observe the ptter i i T( ) T( / ) + i lg T( / ) + lg + lg

Repeted Substitutio Method The procedure is strightforwrd: Substitute Expd Substitute Expd Observe ptter d write how your expressio looks fter the i-th substitutio Fid out wht the vlue of i (e.g., lg ) should be to get the bse cse of the recurrece (sy T()) Isert the vlue of T() d the expressio of i ito your expressio Substitutio method Solve T( ) 4 T( / ) + ) Guess tht T( ) O( ), i.e., tht T of the form c ) Assume ( ) for / d T k ck k ) Prove ( ) by iductio T c T( ) 4 T( / ) + (recurrece) + Thus T( ) O( )! 4c(/) (id. hypoth.) c + (simplify) c c (rerrge) c if c d (stisfy) Subtlety: Must choose c big eough to hdle T( ) Θ () for < for some 0 0 Substitutio method Achievig tighter bouds T Try to show ( ) ( ) Assume Tk ( ) ck T ( ) 4 T ( /) + + 4( c/) + c O > c for o choice of c 0. Substitutio method The problem: We could ot rewrite the equlity s: T ( ) c+ (somethig positive) T ( ) c i order to show the iequlity we wted Sometimes to prove iductive step, try to stregthe your hypothesis T() (swer you wt) - (somethig > 0) Substitutio method Corrected proof: the ide is to stregthe the iductive hypothesis by subtrctig lower-order terms! Assume Tk ( ) ck ck for k< T ( ) 4 T ( /) + 4( c( / ) c( / )) + c c + c c ( c ) c cif c Recursio Tree A recursio tree is coveiet wy to visulize wht hppes whe recurrece is iterted Costructio of recursio tree T ( ) T ( /4) + T ( /) +

Recursio Tree Recursio Tree T ( ) T ( /) + T( /) + Mster Method The ide is to solve clss of recurreces tht hve the form T ( ) Tb ( / ) + f ( ) Mster method d b >, d f is symptoticlly positive! Abstrctly spekig, T() is the rutime for lgorithm d we kow tht subproblems of size /b re solved recursively, ech i time T(/b) f() is the cost of dividig the problem d combiig the results. I merge-sort T ( ) T ( /) +Θ( ) Split problem ito prts t log b levels. There re leves Mster method Number of leves: Itertig the recurrece, expdig the tree yields log log b T ( ) f ( ) + Tb ( / ) b f + f b + T b ( ) ( / ) ( / ) f + f b + T b + ( ) ( / ) ( / )... + f( / b ) + T() log log log b b b Thus, j j ( ) ( / ) ( ) T fb +Θ j 0 The first term is divisio/recombitio cost (totled cross ll levels of the tree) log b The secod term is the cost of doig ll subproblems of size (totl of ll work pushed to leves) Mster method ituitio Three commo cses: Ruig time domited by cost t leves Ruig time evely distributed throughout the tree Ruig time domited by cost t root Cosequetly, to solve the recurrece, we eed oly to chrcterize the domit term I ech cse compre f ( ) with O ( )

Mster method Cse ( ) ( ε f O ) for some costt ε > 0 f() grows polyomilly (by fctor ε ) slower th log b The work t the lef level domites Summtio of recursio-tree levels O ( ) Cost of ll the leves Thus, the overll cost Θ( ) Θ( ) Mster method Cse f ( ) Θ( lg ) log f ( ) d b re symptoticlly the sme The work is distributed eqully throughout the tree T ( ) Θ( lg ) (level cost) (umber of levels) Mster method Cse ( ) ( +ε f Ω ) for some costt Iverse of Cse f() grows polyomilly fster th log b Also eed regulrity coditio c< d > 0 such tht f( / b) cf( ) > The work t the root domites T ( ) Θ( f ( )) ε > 0 0 0 Mster Theorem Summrized Give recurrece of the form T ( ) Tb ( / ) + f ( ) ε. f( ) O( ) T ( ) Θ( ). f( ) Θ( ) T ( ) Θ( lg) +ε. f ( ) Ω( ) d f( / b) cf( ), for some c<, > 0 T ( ) Θ( f ( )) The mster method cot solve every recurrece of this form; there is gp betwee cses d, s well s cses d Usig the Mster Theorem Extrct, b, d f() from give recurrece log Determie b log b Compre f() d symptoticlly Determie pproprite MT cse, d pply Exmple merge sort T ( ) T ( /) +Θ( ) log b log, b ; Θ( ) Also f( ) Θ( ) Cse : T ( ) Θ lg Θ lg ( ) ( ) Exmples T () T (/) + b log, ; lso f (), f () Θ() Cse : T () Θ(lg) T ( ) 9 T ( /) + 9, b ; f f O ε log 9 ε (), () ( ) with Cs e : T () Θ ( ) Biry-serch(A, p, p, r, r, s): s): q (p+r)/ if if A[q]s the the retur q else else if if A[q]>s the the Biry-serch(A, p, p, q-, q-, s) s) else else Biry-serch(A, q+, q+, r, r, s) s)

Exmples Exmples T ( ) T ( /4) + lg, b 4; log4 0.79 f f log4 +ε ( ) lg, ( ) Ω( ) with ε 0. Cse : Regulrity coditio f ( / b) ( /4)lg( / 4) (/ 4) lg cf ( ) for c / 4 T ( ) Θ( lg ) T ( ) T ( /) + lg log, b ; +ε f ( ) lg, f( ) Ω( ) with ε? lso l g / lg either Cse or Cse! T( ) 4 T( /) + 4, b ; log 4 f f Ω ( ) ; ( ) ( ) Cse : T( ) Θ ( ) Checkig the regulrity coditio 4 f( / ) cf( ) 4 /8 c / c c /4< A quick review of logrithms Properties to remember. log (b) log + log b. log (/b) log - log b. log (/) - log 4. log log 5. log Next. Covered bsics of simple desig techique (Divided-coquer) Ch. 4 of the text.. Next, more sortig lgorithms. It follows tht :. log. + log. log (log )