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

Similar documents
Data Structures and Algorithms CMPSC 465

Sequences and summations

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

Section IV.6: The Master Method and Applications

Algorithm Design and Analysis

MTH 146 Class 7 Notes

ITERATIVE METHODS FOR SOLVING SYSTEMS OF LINEAR ALGEBRAIC EQUATIONS

5. Solving recurrences

Advanced Algorithmic Problem Solving Le 3 Arithmetic. Fredrik Heintz Dept of Computer and Information Science Linköping University

Chapter 2 Intro to Math Techniques for Quantum Mechanics

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

ME 501A Seminar in Engineering Analysis Page 1

In Calculus I you learned an approximation method using a Riemann sum. Recall that the Riemann sum is

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

Chapter 2 Intro to Math Techniques for Quantum Mechanics

this is the indefinite integral Since integration is the reverse of differentiation we can check the previous by [ ]

Available online through

POWERS OF COMPLEX PERSYMMETRIC ANTI-TRIDIAGONAL MATRICES WITH CONSTANT ANTI-DIAGONALS

Area and the Definite Integral. Area under Curve. The Partition. y f (x) We want to find the area under f (x) on [ a, b ]

Roberto s Notes on Integral Calculus Chapter 4: Definite integrals and the FTC Section 2. Riemann sums

Optimality of Strategies for Collapsing Expanded Random Variables In a Simple Random Sample Ed Stanek

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

Rendering Equation. Linear equation Spatial homogeneous Both ray tracing and radiosity can be considered special case of this general eq.

Data Structures and Algorithm. Xiaoqing Zheng

12 Iterative Methods. Linear Systems: Gauss-Seidel Nonlinear Systems Case Study: Chemical Reactions

CURVE FITTING LEAST SQUARES METHOD

i+1 by A and imposes Ax

ICS141: Discrete Mathematics for Computer Science I

Asymptotic Dominance Problems. is not constant but for n 0, f ( n) 11. 0, so that for n N f

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

6. Chemical Potential and the Grand Partition Function

DATA FITTING. Intensive Computation 2013/2014. Annalisa Massini

Lecture 3-4 Solutions of System of Linear Equations

Chapter 3 Supplemental Text Material

The z-transform. LTI System description. Prof. Siripong Potisuk

Preliminary Examinations: Upper V Mathematics Paper 1

Stats & Summary

A Brief Introduction to Olympiad Inequalities

Regression. By Jugal Kalita Based on Chapter 17 of Chapra and Canale, Numerical Methods for Engineers

On Several Inequalities Deduced Using a Power Series Approach

Chapter 7. Bounds for weighted sums of Random Variables

Numerical Solution of Second order Integro- Differential Equations(Ides) with Different Four Polynomials Bases Functions

Analytical Approach for the Solution of Thermodynamic Identities with Relativistic General Equation of State in a Mixture of Gases

Data Structures and Algorithms CMPSC 465

COMPLEX NUMBERS AND DE MOIVRE S THEOREM

Patterns of Continued Fractions with a Positive Integer as a Gap

Differential Method of Thin Layer for Retaining Wall Active Earth Pressure and Its Distribution under Seismic Condition Li-Min XU, Yong SUN

Soo King Lim Figure 1: Figure 2: Figure 3: Figure 4: Figure 5: Figure 6: Figure 7: Figure 8: Figure 9: Figure 10: Figure 11:

Linear Open Loop Systems

SUM PROPERTIES FOR THE K-LUCAS NUMBERS WITH ARITHMETIC INDEXES

Answer: First, I ll show how to find the terms analytically then I ll show how to use the TI to find them.

Definite Integral. The Left and Right Sums

On a class of analytic functions defined by Ruscheweyh derivative

14.2 Line Integrals. determines a partition P of the curve by points Pi ( xi, y

The limit comparison test

UNIT I. Definition and existence of Riemann-Stieltjes

4 Linear Homogeneous Recurrence Relation 4-1 Fibonacci Rabbits. 组合数学 Combinatorics

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

Introduction to Group Theory

Section 6.3: Geometric Sequences

The Basic Properties of the Integral

Algorithms and Data Structures Lecture IV

Chapter Gauss-Seidel Method

Approximate Integration

Review of Sections

St John s College. UPPER V Mathematics: Paper 1 Learning Outcome 1 and 2. Examiner: GE Marks: 150 Moderator: BT / SLS INSTRUCTIONS AND INFORMATION

On Solution of Min-Max Composition Fuzzy Relational Equation

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

under the curve in the first quadrant.

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

MATLAB PROGRAM FOR THE NUMERICAL SOLUTION OF DUHAMEL CONVOLUTION INTEGRAL

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

Math 1B, lecture 4: Error bounds for numerical methods

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

Solutions Manual for Polymer Science and Technology Third Edition

The Fundamental Theorem of Calculus. The Total Change Theorem and the Area Under a Curve.

PATTERNS IN CONTINUED FRACTION EXPANSIONS

13: Diffusion in 2 Energy Groups

( a n ) converges or diverges.

Level-2 BLAS. Matrix-Vector operations with O(n 2 ) operations (sequentially) BLAS-Notation: S --- single precision G E general matrix M V --- vector

SOLVING SYSTEMS OF EQUATIONS, DIRECT METHODS

A Technique for Constructing Odd-order Magic Squares Using Basic Latin Squares

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

1 Error Analysis of Simple Rules for Numerical Integration

Review of the Riemann Integral

POWER SERIES R. E. SHOWALTER

MATH2999 Directed Studies in Mathematics Matrix Theory and Its Applications

Introduction to mathematical Statistics

Chapter 7 Infinite Series

Math 2414 Activity 16 (Due by end of class August 13) 1. Let f be a positive, continuous, decreasing function for x 1, and suppose that

Itō Calculus (An Abridged Overview)

Connected-components. Summary of lecture 9. Algorithms and Data Structures Disjoint sets. Example: connected components in graphs

Lecture 20: Numerical Integration III

10.2 Series. , we get. which is called an infinite series ( or just a series) and is denoted, for short, by the symbol. i i n

Strategies for the AP Calculus Exam

Repeated Root and Common Root

The Selection Problem - Variable Size Decrease/Conquer (Practice with algorithm analysis)

Mathematical models for computer systems behaviour

CS537. Numerical Analysis

Abstrct Pell equto s mportt reserch object elemetry umber theory of defte equto ts form s smple, but t s rch ture My umber theory problems ce trsforme

Transcription:

CS473-Algorthms I Lecture 3 Solvg Recurreces Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet

Solvg Recurreces The lyss of merge sort Lecture requred us to solve recurrece. Recurreces re lke solvg tegrls, dfferetl equtos, etc. Ler few trcks. Lecture 4 : Applctos of recurreces. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 2

Recurreces Fucto expressed recursvely T T / 2 f = f > Solve for = 2 k Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 3

Recurreces Clmed swer: T = lg+ = lg Susttute clmed swer for T the recurrece Note: resultg equtos re true whe = 2 k.e. lg lg Tedous techclty: hve t show T = lg / 2 But, sce T s mootoclly o-decresg fucto of lg 2 2 lg T T lg 2 lg f =2 0 = f =2 k > lg lg Thus, celg dd t mtter much Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 4

Recurreces Techclly, should e creful out floors d celgs s the ook But, usully t s oky To gore floor/celg Just solve for exct powers of 2 or Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 5

Boudry Codtos Usully ssume T= Θ for smll Does ot usully ffect sol. f polyomlly ouded Exmple: Itl codto ffects sol. Expoetl T=T / 2 2 E.g., If T= c for costt c > 0, the T2 = T 2 =c 2, T4= T2 2 =c 4, T = Θc T 2 T 2 However 2 3 T 3 T 3 Dfferece sol. s more drmtc wth T T Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 6

Susttuto Method The most geerl method:. Guess the form of the soluto. 2. Verfy y ducto. 3. Solve for costts. Exmple: T = 4T/2 + [Assume tht T = Θ.] Guess O 3. Prove O d Ω seprtely. Assume tht Tk ck 3 for k <. Prove T c 3 y ducto. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 7

Exmple of Susttuto T = 4T/2 + 4c /2 3 + = c/2 3 + = c 3 c/2 3 - desred resdul c 3 wheever c/2 3 0, for exmple, f c 2 d resdul Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 8

Exmple Cotued We must lso hdle the tl codtos, tht s, groud the ducto wth se cses. Bse: T = Θ for ll < 0, where 0 s sutle costt. For < 0, we hve Θ c 3, f we pck c g eough. Ths oud s ot tght! Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 9

A Tghter Upper Boud? We shll prove tht T = O 2 Assume tht Tk ck 2 for k < : T = 4T/2 + c 2 + = O 2 Wrog! We must prove the I.H. = c 2 - - c 2 for o choce of c > 0. Lose! Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 0

A Tghter Upper Boud! IDEA: Stregthe the ductve hypothess. Sutrct low-order term. Iductve hypothess: Tk c k 2 c 2 k for k < T = 4T/2 + 4 c /2 2 - c 2 /2 + = c 2-2 c 2 + = c 2 - c 2 c 2 - c 2 - c 2 f c 2 > Pck c g eough to hdle the tl codtos Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet

Recurso-Tree Method A recurso tree models the costs tme of recursve executo of lgorthm. The recurso tree method s good for geertg guesses for the susttuto method. The recurso-tree method c e urelle. The recurso-tree method promotes tuto, however. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 2

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 3

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : T Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 4

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 T/4 T/2 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 5

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 /4 2 /2 2 T/6 T/8 T/8 T/4 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 6

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 /4 2 /2 2 /6 2 /8 2 /8 2 /4 2 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 7

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 2 /4 2 /2 2 /6 2 /8 2 /8 2 /4 2 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 8

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 2 /4 2 /2 2 5/6 2 /6 2 /8 2 /8 2 /4 2 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 9

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 2 /4 2 /2 2 /6 2 /8 2 /8 2 /4 2 5/6 2 25/256 2 Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 20

Exmple of Recurso Tree Solve T = T/4 + T/2 + 2 : 2 2 /4 2 /2 2 /6 2 /8 2 /8 2 /4 2 5/6 2 25/256 2 Totl = 2 + 5/6 + 5/6 2 + 5/6 2 +... = 2 geometrc seres Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 2

The Mster Method The mster method pples to recurreces of the form T = T/ + f, where, >, d f s symptotclly postve. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 22

Three Commo Cses Compre f wth :. f = O for some costt ε > 0. f grows polyomly slower th y ε fctor. Soluto: T = Θ. 2. f = Θ lg k for some costt k 0. f d grow t smlr rtes. Soluto: T = Θ lg k+. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 23

Three Commo Cses Compre f wth : 3. f = for some costt ε > 0. f grows polyomlly fster th y ε fctor. d f stsfes the regulrty codto tht f / c f for some costt c < Soluto: T = Θ f. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 24

Exmples Ex: T = 4T/2 + =4, =2 = 2 ; f = CASE : f =O 2- ε for ε= T = Θ 2 Ex: T = 4T/2 + 2 =4, =2 = 2 ; f = 2 CASE 2: f = Θ 2 lg 0, tht s, k=0 T = Θ 2 lg Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 25

Exmples Ex: T = 4T/2 + 3 =4, =2 = 2 ; f = 3. CASE 3: f = 2+ ε for ε= d 4 c /2 3 c 3 reg. cod. for c=/2. T = Θ 3 Ex: T = 4T/2 + 2 / lg =4, =2 = 2 ; f = 2 / lg Mster method does ot pply. I prtculr, for every costt ε > 0, we hve ε = lg Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 26

Geerl Method Akr-Bzz T Let p e the uque soluto to k k The, the swers re the sme s for the T mster method, ut wth p sted of Akr d Bzz lso prove eve more geerl result. / / p f Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 27

Ide of Mster Theorem Recurso tree: f f / f / f / h= f / 2 f / 2 f / 2 f f / 2 f / 2 T #leves = h = = T Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 28

Ide of Mster Theorem Recurso tree: f f / f / f / h= f / 2 f / 2 f / 2 f f / 2 f / 2 T CASE : The weght creses geometrclly from the root to the leves. The leves hold costt T frcto of the totl weght. Θ Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 29

Ide of Mster Theorem Recurso tree: f f / f / f / h= f / 2 f / 2 f / 2 f f / 2 f / 2 T CASE 2 : k = 0 The weght s pproxmtely the sme o ech of the levels. Θ T lg Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 30

Ide of Mster Theorem Recurso tree: f f / f / f / h= f / 2 f / 2 f / 2 f f / 2 f / 2 T CASE 3 : The weght decreses geometrclly from the root to the leves. The root holds costt T frcto of the totl weght. Θ f Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 3

Proof of Mster Theorem: Cse d Cse 2 Recll from the recurso tree ote h = lg =tree heght T h f / 0 Lef cost No-lef cost = g Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 32

Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 33 Proof of Cse for some > 0 f O f O f f 0 0 / / h h O O g 0 / h O

Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 34 = A cresg geometrc seres sce > 0 0 0 h h h O h h Cse cot

Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 35 O O O O g O g T Cse cot O Q.E.D.

Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 36 Proof of Cse 2 lmted to k=0 0 0 0 h h h f f f 0 / lg 0 / h g lg T lg lg 0 Q.E.D.

Cocluso Next tme: pplyg the mster method. Cevdet Aykt - Blket Uversty Computer Egeerg Deprtmet 37