Introduction to Algorithms

Similar documents
the recursion-tree method

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

CS473 - Algorithms I

HOMEWORK 5 SOLUTIONS. n!f n (1) lim. ln x n! + xn x. 1 = G n 1 (x). (2) k + 1 n. (n 1)!

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

Full and Complete Binary Trees

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

Appendix: Solving Recurrences [Fa 10] Wil Wheaton: Embrace the dark side! Sheldon: That s not even from your franchise!

1/1 7/4 2/2 12/7 10/30 12/25

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

Math 115 Spring 2011 Written Homework 5 Solutions

5.2 The Master Theorem

Analysis of Algorithms, I

Algorithms and Methods for Distributed Storage Networks 9 Analysis of DHT Christian Schindelhauer

CS/COE

Solutions of Equations in One Variable. Fixed-Point Iteration II

Information Theory and Coding Prof. S. N. Merchant Department of Electrical Engineering Indian Institute of Technology, Bombay

Introduction. Appendix D Mathematical Induction D1

TAKE-AWAY GAMES. ALLEN J. SCHWENK California Institute of Technology, Pasadena, California INTRODUCTION

Lectures 5-6: Taylor Series

Basic Proof Techniques

SECTION 10-2 Mathematical Induction

Properties of sequences Since a sequence is a special kind of function it has analogous properties to functions:

Math 55: Discrete Mathematics

Equations, Inequalities & Partial Fractions

Mathematical Induction. Lecture 10-11

PUTNAM TRAINING POLYNOMIALS. Exercises 1. Find a polynomial with integral coefficients whose zeros include

4.3 Lagrange Approximation

(Quasi-)Newton methods

A Turán Type Problem Concerning the Powers of the Degrees of a Graph

Answer: (a) Since we cannot repeat men on the committee, and the order we select them in does not matter, ( )

3. Mathematical Induction

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

LOGNORMAL MODEL FOR STOCK PRICES

Continued Fractions and the Euclidean Algorithm

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Continued Fractions. Darren C. Collins

Find-The-Number. 1 Find-The-Number With Comps

9.2 Summation Notation

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

SCORE SETS IN ORIENTED GRAPHS

EC3070 FINANCIAL DERIVATIVES

Sample Induction Proofs

Indiana State Core Curriculum Standards updated 2009 Algebra I

Near Optimal Solutions

10.2 Series and Convergence

Big Data: A Geometric Explanation of a Seemingly Counterintuitive Strategy

CS473 - Algorithms I

Wald s Identity. by Jeffery Hein. Dartmouth College, Math 100

Georgia Department of Education Kathy Cox, State Superintendent of Schools 7/19/2005 All Rights Reserved 1

If n is odd, then 3n + 7 is even.

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Overview. Essential Questions. Precalculus, Quarter 4, Unit 4.5 Build Arithmetic and Geometric Sequences and Series

Fast Sequential Summation Algorithms Using Augmented Data Structures

ON THE COMPLEXITY OF THE GAME OF SET.

Does Black-Scholes framework for Option Pricing use Constant Volatilities and Interest Rates? New Solution for a New Problem

Collatz Sequence. Fibbonacci Sequence. n is even; Recurrence Relation: a n+1 = a n + a n 1.

8 Primes and Modular Arithmetic

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

CS 598CSC: Combinatorial Optimization Lecture date: 2/4/2010

6.042/18.062J Mathematics for Computer Science. Expected Value I

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

Randomized algorithms

Mathematics for Algorithm and System Analysis

2.1 The Present Value of an Annuity

BINOMIAL OPTIONS PRICING MODEL. Mark Ioffe. Abstract

Diagonalization. Ahto Buldas. Lecture 3 of Complexity Theory October 8, Slides based on S.Aurora, B.Barak. Complexity Theory: A Modern Approach.

Taylor and Maclaurin Series

Corollary. (f є C n+1 [a,b]). Proof: This follows directly from the preceding theorem using the inequality

Modern Optimization Methods for Big Data Problems MATH11146 The University of Edinburgh

General Framework for an Iterative Solution of Ax b. Jacobi s Method

1 Short Introduction to Time Series

Computing exponents modulo a number: Repeated squaring

We can express this in decimal notation (in contrast to the underline notation we have been using) as follows: b + 90c = c + 10b

Circles in Triangles. This problem gives you the chance to: use algebra to explore a geometric situation

Faster deterministic integer factorisation

Grade Level Year Total Points Core Points % At Standard %

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Numerical Analysis Lecture Notes

Chapter 7. BANDIT PROBLEMS.

Metric Spaces. Chapter Metrics

3.1. Solving linear equations. Introduction. Prerequisites. Learning Outcomes. Learning Style

IB Maths SL Sequence and Series Practice Problems Mr. W Name

Research Tools & Techniques

To discuss this topic fully, let us define some terms used in this and the following sets of supplemental notes.

Optimal Binary Search Trees Meet Object Oriented Programming

This is a square root. The number under the radical is 9. (An asterisk * means multiply.)

csci 210: Data Structures Recursion

What does the number m in y = mx + b measure? To find out, suppose (x 1, y 1 ) and (x 2, y 2 ) are two points on the graph of y = mx + b.

Design Project 2. Sizing of a Bicycle Chain Ring Bolt Set. Statics and Mechanics of Materials I. ENGR 0135 Section 1040.

The Running Time of Programs

Algorithms. Margaret M. Fleck. 18 October 2010

CONTRIBUTIONS TO ZERO SUM PROBLEMS

Every Positive Integer is the Sum of Four Squares! (and other exciting problems)

Course Notes for Math 162: Mathematical Statistics Approximation Methods in Statistics

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

MATH 289 PROBLEM SET 4: NUMBER THEORY

THE SINE PRODUCT FORMULA AND THE GAMMA FUNCTION

1 Error in Euler s Method

Mathematics 31 Pre-calculus and Limits

Transcription:

Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences (slides enhanced by N. Adlai A. DePano) Overview Define what a recurrence is Discuss three methods of solving recurrences Substitution method Recursion-tree method Master method Examples of each method 1

Definition A recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs. Example from MERGE-SORT T(n) = Θ(1) if n=1 2T(n/2) + Θ(n) if n>1 Technicalities Normally, independent variables only assume integral values Example from MERGE-SORT revisited T(n) = Θ(1) if n=1 T( n/2 ) + T( n/2 ) + Θ(n) if n>1 For simplicity, ignore floors and ceilings often insignificant 2

Technicalities Boundary conditions (small n) are also glossed over T(n) = 2T(n/2) + Θ(n) Value of T(n) assumed to be small constant for small n Substitution Method Involves two steps: 1. Guess the form of the solution. 2. Use mathematical induction to find the constants and show the solution works. Drawback: applied only in cases where it is easy to guess at solution Useful in estimating bounds on true solution even if latter is unidentified 3

Substitution Method Example: T(n) = 2T( n/2 ) + n Guess: T(n) = O(n lg n) Prove by induction: T(n) cn lg n for suitable c>0. Inductive Proof We ll not worry about the basis case for the moment we ll choose this as needed clearly we have: T(1) = Θ(1) cn lg n Inductive hypothesis: For values of n < k the inequality holds, i.e., T(n) cn lg n We need to show that this holds for n = k as well. 4

Inductive Proof In particular, for n = k/2, the inductive hypothesis should hold, i.e., T( k/2 ) c k/2 lg k/2 The recurrence gives us: T(k) = 2T( k/2 ) + k Substituting the inequality above yields: T(k) 2[c k/2 lg k/2 ] + k Inductive Proof Because of the non-decreasing nature of the functions involved, we can drop the floors and obtain: T(k) 2[c (k/2) lg (k/2)] + k Which simplifies to: T(k) ck (lg k lg 2) + k Or, since lg 2 = 1, we have: T(k) ck lg k ck + k = ck lg k + (1 c)k So if c 1, T(k) ck lg k Q.E.D. 5

Recursion-Tree Method Straightforward technique of coming up with a good guess Can help the Substitution Method Recursion tree: visual representation of recursive call hierarchy where each node represents the cost of a single subproblem Recursion-Tree Method T(n) = 3T( n/4 ) + Θ(n 2 ) 6

Recursion-Tree Method T(n) = 3T( n/4 ) + Θ(n 2 ) Recursion-Tree Method T(n) = 3T( n/4 ) + Θ(n 2 ) 7

Recursion-Tree Method T(n) = 3T( n/4 ) + Θ(n 2 ) Recursion-Tree Method Gathering all the costs together: T(n) = (3/16) i cn 2 + Θ(n log 43 Σ ) i=0 T(n) log 4 n 1 Σ i=0 (3/16) i cn 2 + o(n) T(n) (1/(1 3/16))cn 2 + o(n) T(n) (16/13)cn 2 + o(n) T(n) = O(n 2 ) 8

Recursion-Tree Method T(n) = T(n/3) + T(2n/3) + O(n) Recursion-Tree Method An overestimate of the total cost: log 3/2 n 1 Σ i=0 T(n) = cn + Θ(n log 3/22 ) Counter-indications: T(n) = O(n lg n) + ω(n lg n) Notwithstanding this, use as guess : T(n) = O(n lg n) 9

Substitution Method Recurrence: T(n) = T(n/3) + T(2n/3) + cn Guess: T(n) = O(n lg n) Prove by induction: T(n) dn lg n for suitable d>0 (we already use c) Inductive Proof Again, we ll not worry about the basis case Inductive hypothesis: For values of n < k the inequality holds, i.e., T(n) dn lg n We need to show that this holds for n = k as well. In particular, for n = k/3, and n = 2k/3, the inductive hypothesis should hold 10

Inductive Proof That is T(k/3) d k/3 lg k/3 T(2k/3) d 2k/3 lg 2k/3 The recurrence gives us: T(k) = T(k/3) + T(2k/3) + ck Substituting the inequalities above yields: T(k) [d (k/3) lg (k/3)] + [d (2k/3) lg (2k/3)] + ck Inductive Proof Expanding, we get T(k) [d (k/3) lg k d (k/3) lg 3] + [d (2k/3) lg k d (2k/3) lg(3/2)] + ck Rearranging, we get: T(k) dk lg k d[(k/3) lg 3 + (2k/3) lg(3/2)] + ck T(k) dk lg k dk[lg 3 2/3] + ck When d c/(lg3 (2/3)), we should have the desired: T(k) dk lg k 11

Master Method Provides a cookbook method for solving recurrences Recurrence must be of the form: T(n) = at(n/b) + f(n) where a 1 and b>1 are constants and f(n) is an asymptotically positive function. Master Method Theorem 4.1: Given the recurrence previously defined, we have: 1. If f(n) = O(n logba ε ) for some constant ε>0, then T(n) = Θ(n logba ) 2. If f(n) = Θ(n logba ), then T(n) = Θ(n logba lg n) 12

Master Method 3. If f(n) = Ω(n logba+ε ) for some constant ε>0, and if af(n/b) cf(n) for some constant c<1 and all sufficiently large n, then T(n) = Θ(f(n)) Example Estimate bounds on the following recurrence: Use the recursion tree method to arrive at a guess then verify using induction Point out which case in the Master Method this falls in 13

Recursion Tree Recurrence produces the following tree: Cost Summation Collecting the level-by-level costs: A geometric series with base less than one; converges to a finite sum, hence, T(n) = Θ(n 2 ) 14

Exact Calculation If an exact solution is preferred: Using the formula for a partial geometric series: Exact Calculation Solving further: 15

Master Theorem (Simplified) 16