T(n)=1 for sufficiently small n

Similar documents
the recursion-tree method

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

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

CS473 - Algorithms I

Research Tools & Techniques

csci 210: Data Structures Recursion

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

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA === Homework submission instructions ===

Linear Equations and Inequalities

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

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

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

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!

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,

Full and Complete Binary Trees

Section IV.1: Recursive Algorithms and Recursion Trees

Data Structures. Algorithm Performance and Big O Analysis

Math 55: Discrete Mathematics

Indiana State Core Curriculum Standards updated 2009 Algebra I

3. Mathematical Induction

The Running Time of Programs

Sample Induction Proofs

Analysis of Algorithms I: Binary Search Trees

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

The Epsilon-Delta Limit Definition:

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

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

Introduction. Appendix D Mathematical Induction D1

5.2 The Master Theorem

Lecture 6 Online and streaming algorithms for clustering

CS/COE

Prentice Hall: Middle School Math, Course Correlated to: New York Mathematics Learning Standards (Intermediate)

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

Lecture Notes on Polynomials

recursion, O(n), linked lists 6/14

Grade Level Year Total Points Core Points % At Standard %

Course Syllabus. MATH 1350-Mathematics for Teachers I. Revision Date: 8/15/2016

How To Know If A Domain Is Unique In An Octempo (Euclidean) Or Not (Ecl)

MACM 101 Discrete Mathematics I

CS473 - Algorithms I

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

Some facts about polynomials modulo m (Full proof of the Fingerprinting Theorem)

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

No Solution Equations Let s look at the following equation: 2 +3=2 +7

Outline. NP-completeness. When is a problem easy? When is a problem hard? Today. Euler Circuits

Welcome to Math Video Lessons. Stanley Ocken. Department of Mathematics The City College of New York Fall 2013

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

Faster deterministic integer factorisation

Data Structures and Algorithms Written Examination

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

Some Polynomial Theorems. John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA

Dynamic Programming. Lecture Overview Introduction

Lecture 1: Course overview, circuits, and formulas

Homework until Test #2

Mathematical Induction. Lecture 10-11

Continued Fractions and the Euclidean Algorithm

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

8 Primes and Modular Arithmetic

Basics of Counting. The product rule. Product rule example. 22C:19, Chapter 6 Hantao Zhang. Sample question. Total is 18 * 325 = 5850

About the inverse football pool problem for 9 games 1

Computational Geometry Lab: FEM BASIS FUNCTIONS FOR A TETRAHEDRON

Closest Pair Problem

Solutions to Homework 6 Mathematics 503 Foundations of Mathematics Spring 2014

Solutions for Practice problems on proofs

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

Lecture 4 Online and streaming algorithms for clustering

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

Math 115 Spring 2011 Written Homework 5 Solutions

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

PRIME FACTORS OF CONSECUTIVE INTEGERS

Analysis of Algorithms I: Optimal Binary Search Trees

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

From Binomial Trees to the Black-Scholes Option Pricing Formulas

LAKE ELSINORE UNIFIED SCHOOL DISTRICT

Investigation of Chebyshev Polynomials

5.4 Closest Pair of Points

PRE-CALCULUS GRADE 12

CMSC 858T: Randomized Algorithms Spring 2003 Handout 8: The Local Lemma

SHARP BOUNDS FOR THE SUM OF THE SQUARES OF THE DEGREES OF A GRAPH

Math Placement Test Study Guide. 2. The test consists entirely of multiple choice questions, each with five choices.

Access Code: RVAE4-EGKVN Financial Aid Code: 6A9DB-DEE3B-74F

Data Structure [Question Bank]

Week 1: Introduction to Online Learning

Algorithms. Margaret M. Fleck. 18 October 2010

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

Computing exponents modulo a number: Repeated squaring

Examples of Tasks from CCSS Edition Course 3, Unit 5

Revised Version of Chapter 23. We learned long ago how to solve linear congruences. ax c (mod m)

Near Optimal Solutions

Taylor and Maclaurin Series

Dynamic Programming Problem Set Partial Solution CMPSC 465

The Heat Equation. Lectures INF2320 p. 1/88

LECTURE 15: AMERICAN OPTIONS

Algebra I. In this technological age, mathematics is more important than ever. When students

parent ROADMAP MATHEMATICS SUPPORTING YOUR CHILD IN HIGH SCHOOL

2.1 The Present Value of an Annuity

Transcription:

Chapter 4. Recurrences

Outline Offers three methods for solving recurrences, that is for obtaining asymptotic bounds on the solution In the substitution method,, we guess a bound and then use mathematical induction to prove our guess correct The recursion-tree method converts the recurrence into a tree whose nodes represent the costs incurred at various levels The master method provides bounds for the recurrence of the form T ( n) at ( n / b) f ( n) a 1, b 1

Technicalities Assumption of integer arguments to functions Boundary conditions we usually ignore The recurrences that arises from the running time of algorithms generally have T(n)= (1) for sufficiently small n Changing the value of T(1), the solution typically does not change by more than a constant factor,, so the order of growth is unchanged. Often omit floors, ceilings and boundary conditions We forge ahead without these details and later determine whether or not they matter and it is important to know when they do matter.

Recurrence When an algorithm contains a recursive call to itself, its running time can often be described by a recurrence A recurrence is a function (equation or in-equality) defined in terms of one or more base cases, --boundary condition itself, with smaller arguments. Example: T (n) = 1 if n = 1, T (n-1) +1 if n > 1. Solution: T (n) = n. T (n) = 1 2T T (n/2) + n Solution: T (n) = n lg n + n if n = 1, if n 1.

Summary In algorithm analysis, we usually express both the recurrence and its solution using asymptotic notation Example: T(n)=2T(n/2)+ (n), (n), with solution T(n)= (nlgn) The boundary conditions are usually expressed as T(n)=1 for sufficiently small n When we desire an exact rather than asymptotic solution, we need to deal with boundary condition In practice, we just use asymptotic notations most of the time and we ignore boundary conditions

Substitution Method The substitution method entails two steps Guess the form of the solution Use mathematical induction to find the constants and show that the solution works The method is powerful but only applied to cases when it is easy to guess the form of he answer The method can be used to establish either upper or lower bound on a recurrence.

The Substitution method T(n) = 2T(n/2) + n Guess: T(n) = O(n lg n) Proof: Prove that T(n) c n lg n for c>0 Assume T(n/2) c(n/2)lg(n/2) for some positive constant c then T(n) 2(c n/2 lg n/2) + n = cn lg n cn + n cn lg n if c 1 Therefore, T(n) = O(n lg n)

T ( n) O( nlg n) T ( n) ( nlg n) T( n) ( nlg n)

Subtleties There are times when can correctly guess an asymptotic bound on the solution of a recurrence, but somehow the math doesn t seem to work out in the induction Revising the guess by subtracting a lower-order order term often permits the math to go through

Making good guess Avoiding pitfalls Changing variables Several Points T ( n) 2T n lg n m n 2 m lg n m m/2 T (2 ) 2 T (2 ) m m S( m) T (2 ) S( m) 2 S( m / 2) m S( m) O( mlg m) T ( n) S( m) O(lg nlg lg n)

The Recursion-Tree method Each code represents the cost of a single sub-problem somewhere in the set of recursive function invocations. Sum the costs within each level of the tree to obtain a set of per-level costs. Then sum all the per-level costs to determine the total cost of all levels of the recursion. It s useful to solve the recurrence which describes the running time of a divide-and-conquer algorithm. It s used to generate a good guess which is then verified by the substitution method. A careful drawing of a recursion tree and summing the costs can be used as a direct proof of a solution to a recurrence.

Examples T(n)=3T(n/4)+cn 2 Substitution Method Recursion Tree T(n)=T(n/3)+T(2n/3)+O(n)

#nodes at i th level: 3 i Size of subproblem at i th : n/4 i =>total level: log 4 n

Validation

Another Example

Use Substitution Method to verify

Example 1. T (n) = 5T T (n/2) + (n²) vs. n² sol.) Since log2 5 - = 2 for some constant > 0, use Case 1. 2. T (n) = 5T T (n/2) + (n³) vs. n³ sol.) Now lg 5 + = 3 for some constant > 0 Use Case 3 T (n) = (n³) 3. T (n) = 27T T (n/3) + (n³/ lg n) vs. sol) Cannot use the master method. for any k 0.

Homework 4.3-4, 4, 4.3-6 4.4-6 4.5-4