COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones.

Slides:



Advertisements
Similar presentations
Week 6 - Wednesday CS322.
Advertisements

Mixed Recursion: Sec. 8.4 Exercise 3. The closed-form formula for the Towers of Hanoi problem, M n = 2 n – 1, can be proved by mathematical induction.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Recursion, Divide and Conquer Lam Chi Kit (George) HKOI2007.
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
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.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Discrete Structures Chapter 6 Recurrence Relations
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Recursion.
1 Recursion, Recurrences and Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Recurrences Part 3. Recursive Algorithms Recurrences are useful for analyzing recursive algorithms Recurrence – an equation or inequality that describes.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 5. Recursive Algorithms.
Recurrence Relations Connection to recursive algorithms Techniques for solving them.
Chapter 8 With Question/Answer Animations 1. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
Analysis of Recursive Algorithms October 29, 2014
Divide-and-Conquer 7 2  9 4   2   4   7
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Computer Science: A Structured Programming Approach Using C1 6-9 Recursion In general, programmers use two approaches to writing repetitive algorithms.
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
1 Recurrences Algorithms Jay Urbain, PhD Credits: Discrete Mathematics and Its Applications, by Kenneth Rosen The Design and Analysis of.
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2.5 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
RECURRENCE Sequence Recursively defined sequence
DR. NAVEED AHMAD DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF PESHAWAR LECTURE-5 Advance Algorithm Analysis.
Sequences and Summations
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Fall 2015 COMP 2300 Discrete Structures for Computation Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Recurrence Relation Models
Lecture 5 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Chapter 6.1: Recurrence Relations Discrete Mathematical Structures: Theory and Applications.
Recursive Algorithms A recursive algorithm calls itself to do part of its work The “call to itself” must be on a smaller problem than the one originally.
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
RECURRENCE Sequence Recursively defined sequence
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
Chapter 4: Solution of recurrence relationships Techniques: Substitution: proof by induction Tree analysis: graphical representation Master theorem: Recipe.
1 RECURRENCE 1. Sequence 2. Recursively defined sequence 3. Finding an explicit formula for recurrence relation.
Mathematical Analysis of Recursive Algorithm CSG3F3 Lecture 7.
COMP 170 L2 Page 1 Review for Midterm 2 Part II: Number Theory and Cryptography L06: RSA Part III: Logic L07, L08, L09 Part IV: Induction and Recurrence.
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.
CSG523/ Desain dan Analisis Algoritma
CSG523/ Desain dan Analisis Algoritma
Tower of Hanoi problem: Move the pile of rings from one peg to another
Equal costs at all levels
Introduction to Algorithms: Divide-n-Conquer Algorithms
Introduction to Algorithms: Recurrences
COMP108 Algorithmic Foundations Divide and Conquer
Divide-and-Conquer 6/30/2018 9:16 AM
Lecture Outline for Recurrences
Algorithm Analysis (for Divide-and-Conquer problems)
Divide-and-Conquer 7 2  9 4   2   4   7
Tower of Hanoi problem: Move the pile of rings from one peg to another
The Hanoi Tower Problem
CS 2210 Discrete Structures Advanced Counting
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
1A Recursively Defined Functions
Divide-and-Conquer 7 2  9 4   2   4   7
Tower of Hanoi problem: Move the pile of rings from one peg to another
Presentation transcript:

COMP 170 L2 L11: Recursion, Recurrence, and Induction l Objective n Recursion  A problem solving technique that reduces big problems into smaller ones n Induction  Proving correctness of recursive programs n Recurrence  Running time for recursive programs Page 1

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n One type of First-Order linear recurrences n Another type of First-Order linear recurrences Page 2

COMP 170 L2 Page 3

COMP 170 L2 Page 4

COMP 170 L2 Page 5

COMP 170 L2 Recursive Solution of Towers of Hanoi Page 6

COMP 170 L2 Recursive Solution of Towers of Hanoi Page 7

COMP 170 L2 Recursive Solution of Towers of Hanoi l Task: n Move n disks from peg i to peg j l Algorithm n Recursion base:  When n=1, move one disk from i to j n Recursion Page 8

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n Geometric serious n First-Order linear recurrences Page 9

COMP 170 L2 Correctness of Algorithm Page 10

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n One type of First-Order linear recurrences n Another type of First-Order linear recurrences Page 11

COMP 170 L2 Running Time Page 12

COMP 170 L2 Solving the Recurrence Page 13

COMP 170 L2 Page 14

COMP 170 L2 Page 15

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n One type of First-Order linear recurrences n Another type of First-Order linear recurrences Page 16

COMP 170 L2 Recurrence l Recurrence/recurrence equation is a way to specify functions on the set of integers l It tells us how to n get the n-th value f(n) n from the first n-b values: f(b), f(b+1), …, f(n-1) l Need to give the value for the base case f(b) to complete the description Page 17

COMP 170 L2 Number of subsets l S(n): number of subsets of set {1, 2, 3, …., n} of size n l Question: n How to compute S(n) from S(n-1), S(n-2), …? l Consider the case: n=3 n First row: subsets of {1, 2} n Second: subsets of {1, 2}, each adjoined by 3 n So: S(3) = 2 S(2) Page 18

COMP 170 L2 Number of Subsets l In general, subsets of set {1, 2, 3, …., n} can be divided into two groups n subsets of set {1, 2, 3, …., n-1} n subsets of set {1, 2, 3, …., n-1}, each adjoined by n. n So: S(n) = 2 S(n-1) l Base case: n S(0) =1 Page 19

COMP 170 L2 Page 20

COMP 170 L2 Monthly Payment for Loan l Initial loan amount: A l Annual interest rate: p l Monthly Payment: M l T(n): total amount still due after n months Page 21

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n One type of First-Order linear recurrences n Another type of First-Order linear recurrences Page 22

COMP 170 L2 Page 23

COMP 170 L2 One Type of First-Order Linear Recurrence Examples Page 24

COMP 170 L2 Iterating the Recurrence/Top-Down Page 25

COMP 170 L2 Iterating the Recurrence/Bottom-Up Page 26

COMP 170 L2 Page 27

COMP 170 L2 One Type of First-Order Linear Recurrence Page 28

COMP 170 L2 Page 29

COMP 170 L2 Page 30

COMP 170 L2 Example Page 31

COMP 170 L2 An Application of Theorem 4.1 Geometric Series Page 32

COMP 170 L2 Outline l Recursive algorithm for Towers of Hanoi n Problem and algorithm n Correctness n Running time l Recurrence in general n Example: Number of subsets n Example: Loan repayment l Solving recurrences n One type of First-Order linear recurrence n Another type of First-Order linear recurrence Page 33

COMP 170 L2 Page 34 Another Type of First-Order Linear Recurrence

COMP 170 L2 Page 35

COMP 170 L2 Page 36

COMP 170 L2 Page 37

COMP 170 L2 Page 38

COMP 170 L2 Page 39