Proofs, Recursion and Analysis of Algorithms

Slides:



Advertisements
Similar presentations
Week 6 - Wednesday CS322.
Advertisements

Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
11 Computer Algorithms Lecture 6 Recurrence Ch. 4 (till Master Theorem) Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
1 Recursion, Recurrences and Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Recurrence Relations Reading Material –Chapter 2 as a whole, but in particular Section 2.8 –Chapter 4 from Cormen’s Book.
Set, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Chapter 4 Section 2 Copyright © 2011 Pearson Education, Inc.
Induction and recursion
Analysis of Recursive Algorithms October 29, 2014
1 © 2010 Pearson Education, Inc. All rights reserved 10.1 DEFINITION OF A SEQUENCE An infinite sequence is a function whose domain is the set of positive.
Rev.S08 MAC 1140 Module 12 Introduction to Sequences, Counting, The Binomial Theorem, and Mathematical Induction.
Chapter 6 Mathematical Induction
Analysis of Algorithms
Chapter 7 Recursion 1CSCI 3333 Data Structures. 2 Recurrent Sequence A recursively defined sequence – First, certain initial values are specified  c.f.,
Project 2 due … Project 2 due … Project 2 Project 2.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2.5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Chapter 2 Mathematical preliminaries 2.1 Set, Relation and Functions 2.2 Proof Methods 2.3 Logarithms 2.4 Floor and Ceiling Functions 2.5 Factorial and.
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
1 Topics Recursion sections 8.1 – Recursion A recursively defined sequence –First, certain initial values are specified –Later terms of the sequence.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 3.
Introduction to Algorithms Chapter 4: Recurrences.
CSE 2813 Discrete Structures Solving Recurrence Relations Section 6.2.
Foundations II: Data Structures and Algorithms
ADVANCED ALGORITHMS REVIEW OF ANALYSIS TECHNIQUES (UNIT-1)
Solving Recurrences with the Substitution Method.
1Computer Sciences. 2 GROWTH OF FUNCTIONS 3.2 STANDARD NOTATIONS AND COMMON FUNCTIONS.
Introduction to Algorithms (2 nd edition) by Cormen, Leiserson, Rivest & Stein Chapter 4: Recurrences.
1 2/21/2016 MATH 224 – Discrete Mathematics Sequences and Sums A sequence of the form ar 0, ar 1, ar 2, ar 3, ar 4, …, ar n, is called a geometric sequence.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach a particular.
1 Lecture Outline for Recurrences Already Covered: Recursive definition of sequences Recursive definition of sets Recursive definition of operations Recursive.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Recursive Definitions
Chapter 4: Induction and Recursion
Recursion Ali.
Mathematical Foundations (Solving Recurrence)
MATH 224 – Discrete Mathematics
Recursion and Recurrence Relations
Analysis of Algorithms CS 477/677
Introduction to Algorithms: Recurrences
Modeling with Recurrence Relations
Introduction to Recurrence Relations
We will be looking for a solution to the system of linear differential equations with constant coefficients.
Induction and recursion
Induction and Recursion
A second order ordinary differential equation has the general form
Design and Analysis of Algorithms
Lecture Outline for Recurrences
Proofs, Recursion and Analysis of Algorithms
Ch 5.2: Series Solutions Near an Ordinary Point, Part I
Induction and recursion
ICS 353: Design and Analysis of Algorithms
Recurrences (Method 4) Alexandra Stefan.
Copyright © Cengage Learning. All rights reserved.
Solving Recurrence Relations
Mathematical Induction
Divide and Conquer (Merge Sort)
Copyright © Cengage Learning. All rights reserved.
At the end of this session, learner will be able to:
Mathematical Induction
ICS 353: Design and Analysis of Algorithms
Copyright © Cengage Learning. All rights reserved.
Presentation transcript:

Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co. MSCS Slides Proofs, Recursion and Analysis of Algorithms

Properties of recurrence relations A linear recurrence relation can be written as S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n) where f’s and g are or can be expressions involving n. Linearity, homogeneity and orders A linear relation is when the earlier values in the definition of S(n) as shown above have power 1. The term linear means that each term of the sequence is defined as a linear function of the preceding terms. Example: F(n) = F(n-1) + F(n-2) A nonlinear relation is the one that has earlier values in the definition as powers other than 1. Example: F(n+1) = 2nF(n-1)(1-F(n-1)) Solutions are quite complex. Homogenous relation is a relation that has g(n) = 0 for all n Example: a(n) – a(n-1) = 2n Inhomogenous relation: Example: S(n) = 2S(n-1) Section 2.5 Recurrence Relations

Order of Recurrence Relation A recurrence relation is said to have constant coefficients if the f’s are all constants. Fibonaci relation is homogenous and linear: F(n) = F(n-1) + F(n-2) Non-constant coefficients: T(n) = 2nT(n-1) + 3n2T(n-2) Order of a relation is defined by the number of previous terms in a relation for the nth term. First order: S(n) = 2S(n-1) nth term depends only on term n-1 Second order: F(n) = F(n-1) + F(n-2) nth term depends only on term n-1 and n-2 Third Order: T(n) = 3nT(n-2) + 2T(n-1) + T(n-3) nth term depends only on term n-1 and n-2 and n-3 Section 2.5 Recurrence Relations

Solving recurrence relations Solving a recurrence relation employs finding a closed-form solution for the recurrence relation. An equation such as S(n) = 2n, where we can substitute a value for n and get the output value back directly, is called a closed-form solution. Two methods used to solve a recurrence relation: Expand, Guess Verify Repeatedly uses the recurrence relation to expand the expression for the nth term until the general pattern can be guessed. Finally the guess is verified by mathematical induction. Solution from a formula Known solution formulas can be derived for some types of recurrence relations. Section 2.5 Recurrence Relations

Expand, guess and verify Show that S(n) = 2n for the following recurrence relation: S(1) = 1 S(n) = 2S(n-1) for n  2 Expansion: Using the recurrence relation over again everytime S(n) = 2S(n-1)  S(n) = 2(2S(n-2)) = 22S(n-2)  S(n) = 22(2S(n-3)) = 23S(n-3) Looking at the developing pattern, we guess that after k such expansions, the equation has the form S(n) = 2kS(n-k) This should stop when n-k =1, hence k = n-1, As the base case provided is S(1) S(n) = 2n-1S(1)  S(n) = 2.2n-1 = 2n Do the verification step by assuming the closed form solution for S(k) and proving S(k+1) Section 2.5 Recurrence Relations

Verification Step for Expand, Guess & Verify Confirm derived closed-form solution by induction on the value of n. Statement to prove: S(n) = 2n for n  2. For the basis step, S(l) = 21. This is true since S(1) is provided in the problem. Assume that S(k) = 2k. Then S(k+1) = 2S(k) (by using the recurrence relation definition) S(k+1) = 2(2k) (by using the above inductive hypothesis)  S(k+1) = 2k+1 This proves that our closed-form solution is correct. Section 2.5 Recurrence Relations

Class Exercise Find the solution for the following recurrence relation: T(1) = 1 T(n) = T(n-1) + 3 for n  2 Solution: T(n) = T(n-1) + 3 = [T(n-2)+3] + 3 = T(n-2)+2*3 = [T(n-3)+3] + 2*3 = T(n-2) + 3*3 In general, we guess that T(n) = T(n-k) + k*3 When n-k = 1, i.e. k = n-1 T(n) = T(1) + (n-1)*3 = 1 + (n-1)*3 = 3*n-2 Prove the above by induction: T(1) = 3(1)-2 = 1, true Assume T(k) = 3*k-2, show T(k+1) = 3*(k+1) +1 = 3*k+1 T(k+1) = T(k) + 3 from the given recurrence relation T(k+1) = 3*k-2+3 by inductive hypothesis Hence, T(k+1) = 3*k+1 Section 2.5 Recurrence Relations

Solution from a formula Solution formula for linear first order constant coefficient relation S(n) = f1(n)S(n-1) + f2(n)S(n-2) + …..+ fk(n)S(n-k) + g(n) For the relation S(n) = 2S(n-1), we have f1(n) = 2 and g(n) = 0 So, S(n) = cS(n-1) + g(n) S(n) = c[cS(n-2)+g(n-1)] + g(n) = c[c[cS(n-3)+g(n-2)] + g(n-1)] + g(n) . S(n) = ckS(n-k) + ck-1g(n-(k-1)) + …..+ cg(n-1) + g(n) The lowest value of n-k is 1 Hence, S(n) = cn-1S(1) + cn-2g(2) + cn-3g(3) +….+ g(n) For S(n) = 2S(n-1), c = 2 and g(n) = 0 Hence, S(n) = 2n-1*S(1) = 2.2n-1 = 2n since S(1) = 2 Section 2.5 Recurrence Relations

Class Exercise Show that the solution for the recurrence relation S(n) = 2S(n-1) + 3 for n  2 and given S(1) = 4 Here, g(n) = 3 and c = 2 given by T(n) = T(n-1) + (n+1) for n  2 and given T(1) = 2 Here, g(n) = 1 and c = n+1 Solutions for these exercises is in the text (pg. 151-152) Section 2.5 Recurrence Relations