R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
1 Recursive Algorithm Analysis Dr. Ying Lu RAIK 283: Data Structures & Algorithms September 13, 2012.
CS 2210 (22C:19) Discrete Structures Advanced Counting
Recurrences. What is a Recurrence Relation? A system of equations giving the value of a function from numbers to numbers in terms of the value of the.
Recursion CSC 220: Data Structure Winter Introduction A programming technique in which a function calls itself. One of the most effective techniques.
Lesson 19 Recursion CS1 -- John Cole1. Recursion 1. (n) The act of cursing again. 2. see recursion 3. The concept of functions which can call themselves.
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
CSE115/ENGR160 Discrete Mathematics 04/19/12 Ming-Hsuan Yang UC Merced 1.
Discrete Structures Chapter 6 Recurrence Relations
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 14: Recursion by.
Recursion.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19: Recursion.
Analysis of Algorithm Lecture 3 Recurrence, control structure and few examples (Part 1) Huma Ayub (Assistant Professor) Department of Software Engineering.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 14: Recursion Starting Out with C++ Early Objects
1 R. Johnsonbaugh, Discrete Mathematics Chapter 4 Algorithms.
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1.
Reynolds 2006 Complexity1 Complexity Analysis Algorithm: –A sequence of computations that operates on some set of inputs and produces a result in a finite.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
15-1 Chapter-18: Recursive Methods –Introduction to Recursion –Solving Problems with Recursion –Examples of Recursive Methods.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Chapter Objectives To understand how to think recursively
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
RECURRENCE Sequence Recursively defined sequence
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
Discrete Mathematics Recurrence Relations Chapter 5 R. Johnsonbaugh
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
CHAPTER TWO RECURRENCE RELATION
 Every year Stephanie’s hamster population doubles. She started with 6 hamsters. How many hamsters does she have after 7 years? After n years?
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
RECURRENCE Sequence Recursively defined sequence
Lecture 2 What is a computational problem? What is an instance of a problem? What is an algorithm? How to guarantee that an algorithm is correct? What.
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation.
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
1 In this puzzle, the player begins with n disks of decreasing diameter placed one on top of the other on one of three pegs of the game board. The player.
Discrete Math For Computing II. Contact Information B. Prabhakaran Department of Computer Science University of Texas at Dallas Mail Station EC 31, PO.
CSG523/ Desain dan Analisis Algoritma
CSG523/ Desain dan Analisis Algoritma
Chapter 19: Recursion.
Recursion and Recurrence Relations
Chapter 15 Recursion.
Modeling with Recurrence Relations
Chapter 15 Recursion.
A0=0 a1=2 an a2=6 an-1 a3=12 a4=20 a2 a1 a0.
Introduction to Recurrence Relations
Module #17: Recurrence Relations
Chapter 14: Recursion Starting Out with C++ Early Objects
Chapter 14: Recursion Starting Out with C++ Early Objects
Module #17: Recurrence Relations
Recursion and Recurrence Relations
CS 2210 Discrete Structures Advanced Counting
Recursion.
Chapter 19: Recursion.
Chapter 7 Advanced Counting Techniques
Chapter 3 :Recursion © 2011 Pearson Addison-Wesley. All rights reserved.
Recurrence Relations Rosen 5th ed., §6.2 5/22/2019
Divide-and-conquer approach
Presentation transcript:

R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 5 Recurrence Relations

5.1 Introduction A recurrence relation  is an infinite sequence a 1, a 2, a 3,…, a n,…  in which the formula for the nth term a n depends on one or more preceding terms,  with a finite set of start-up values or initial conditions

Examples of recurrence relations  Example 1: Initial condition a 0 = 1 Recursive formula: a n = 1 + 2a n-1 for n > 2 First few terms are: 1, 3, 7, 15, 31, 63, …  Example 2: Initial conditions a 0 = 1, a 1 = 2 Recursive formula: a n = 3(a n-1 + a n-2 ) for n > 2 First few terms are: 1, 2, 9, 33, 126, 477, 1809, 6858, 26001,…

Fibonacci sequence  Initial conditions: f 1 = 1, f 2 = 2  Recursive formula: f n+1 = f n-1 + f n for n > 3  First few terms: n fnfn

Compound interest  Given P = initial amount (principal) n = number of years r = annual interest rate A = amount of money at the end of n years At the end of:  1 year: A = P + rP = P(1+r)  2 years: A = P + rP(1+r) = P(1+r) 2  3 years: A = P + rP(1+r) 2 = P(1+r) 3 …  Obtain the formula A = P (1 + r) n

Towers of Hanoi Start with three pegs numbered 1, 2 and 3 mounted on a board, n disks of different sizes with holes in their centers, placed in order of increasing size from top to bottom.  Object of the game: find the minimum number of moves needed to have all n disks stacked in the same order in peg number 3.

Rules of the game: Hanoi towers Start with all disks stacked in peg 1 with the smallest at the top and the largest at the bottom Use peg number 2 for intermediate steps Only a disk of smaller diameter can be placed on top of another disk

End of game: Hanoi towers Game ends when all disks are stacked in peg number 3 in the same order they were stored at the start in peg number 1. Verify that the minimum number of moves needed is the Catalan number C 3 = 5. Start End

5.2 Solving recurrence relations Two main methods:  Iteration  Method for linear homogeneous recurrence relations with constant coefficients

5.3 Applications to the analysis of algorithms 1. Selection sorting a) Given a sequence of n terms a k, k = 1, 2,…, n to be arranged in increasing order b) Count the number of comparisons b n with initial condition b 1 = 0 c) Obtain recursion relation b n = n – 1 + b n-1 for n = 1, 2, 3,… d) b n = n(n-1)/2 =  (n 2 )

Selection Sort function selection_sort(s,n) begin if( n == 1) return(); max_index = 1 for i = 2 to n if (s[i] > s[max_index] then max_index = i endif endfor swap(s[n], s[max_index]) selection_sort(s, n-1) end

Binary search 2. Problem: Search for a value in an increasing sequence. Return the index of the value, or 0 if not found.  Initial condition a 1 = 2  Recurrence relation a n = 1 + a  n/2   Result: a n =  (lg n)

Binary_search Function binary_search(s, I, j, key) Begin if( I > j) return(0) endif middle = (i+j) /2 

Binary_search (cont.) if( s[middle] = key) then return(middle) if( s[middle] > key) then j = middle -1 else i = middle + 1 endif binary_search( i, j, key) end

Merging two sequences 3. Problem: Combine two increasing sequences into a single increasing sequence (merge two sequences).  Theorem 5.3.7: To merge two sequences the sum of whose lengths is n, the number of comparisons required is n-1.

Merge Function merge(s, I, m, j, c) Begin p = I q = m+1 r = I

Merge while( p <= m and q <= j) if( s[p] < s[q]) c[r] = s[p] p = p+1 else c[r] = s[q] q = q+1 endif r = r+1 endwhile

Merge while( p <=m) c[r] = s[p] p = p+1 r = r+1 endwhile while( q <=j) c[r] = s[q] q = q+1 r = r+1 endwhile end

Merge sort 4. A recursive algorithm is used to sort a sequence into increasing order using the algorithm for merging two increasing sequences into one increasing sequence (merge sort).  Theorem : The merge sort algorithm is (n lg n) in the worst case.

Merge_sort Function merge_sort( s, I, j) Begin if( I =j) return() m =  (i+j) /2  merge_sort(s, I, m) merge_sort( s, m+1, n) merge(s, I, m, j, c)

Merge_sort for k = 1 to j s[k] = c[k] endfor end