DOC PREVIEW
UNL CSCE 235 - Recursion

This preview shows page 1-2-3-4-5-38-39-40-41-42-43-77-78-79-80-81 out of 81 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 81 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

IntroductionRecurrence RelationsLinear Homogeneous Recurrences2nd OrderGeneralNonhomogeneousOther MethodsBack SubstitutionRecurrence TreesMapleRecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecursionSlides by Christopher M. BourkeInstructor: Berthe Y. ChoueirySpring 2006Computer Science & Engineering 235Introduction to Discrete MathematicsSections 6.1 - 6.2 of [email protected] / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecursive AlgorithmsA recursive algorithm is one in which objects are defined interms of other objects of the same type.Advantages:Simplicity of codeEasy to understandDisadvantages:MemorySpeedPossibly redundant workTail recursion offers a solution to the memory problem, butreally, do we need recursion?2 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecursive AlgorithmsAnalysisWe’ve already seen how to analyze the running time ofalgorithms. However, to analyze recursive algorithms, werequire more sophisticated techniques.Specifically, we study how to define & solve recurrencerelations.3 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorialRecall the factorial function.n! =1 if n = 1n · (n − 1)! if n > 1Consider the following (recursive) algorithm for computing n!:Algorithm (Factorial)Input : n ∈ NOutput : n!if n = 1 then1return 12end3else4return Factorial(n − 1) × n5end64 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.5 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.6 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.7 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.8 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.9 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsMotivating ExampleFactorial - Analysis?How many multiplications M(n) does Factorial perform?When n = 1 we don’t perform any.Otherwise we perform 1.Plus how ever many multiplications we perform in therecursive call, Factorial(n − 1).This can be expressed as a formula (similar to thedefinition of n!.M(0) = 0M(n) = 1 + M (n − 1)This is known as a recurrence relation.10 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecurrence Relations IDefinitionDefinitionA recurrence relation for a sequence {an} is an equation thatexpresses anin terms of one or more of the previous terms inthe sequence,a0, a1, . . . , an−1for all integers n ≥ n0where n0is a nonnegative integer.A sequence is called a solution of a recurrence relation if itsterms satisfy the recurrence relation.11 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecurrence Relations IIDefinitionConsider the recurrence relation: an= 2an−1− an−2.It has the following sequences anas solutions:1an= 3n,2an= 2n, and3an= 5.Initial conditions + recurrence relation uniquely determine thesequence.12 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecurrence Relations IIIDefinitionExampleThe Fibonacci numbers are defined by the recurrence,F (n) = F (n − 1) + F (n − 2)F (1) = 1F (0) = 1The solution to the Fibonacci recurrence isfn=1√5 1 +√52!n−1√5 1 −√52!n(your book derives this solution).13 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecurrence Relations IVDefinitionMore generally, recurrences can have the formT (n) = αT (n − β) + f(n), T (δ) = corT (n) = αTnβ+ f(n), T (δ) = cNote that it may be necessary to define several T (δ), initialconditions.14 / 81RecursionCSE235IntroductionRecurrenceRelationsLinearHomogeneousRecurrencesNon-homogenousOtherMethodsRecurrence Relations VDefinitionThe initial conditions specify the value of the first fewnecessary terms in the sequence. In the Fibonacci numbers weneeded two initial conditions, F (0) = F (1) = 1 since F (n) wasdefined by the two previous terms in the sequence.Initial conditions are also known as boundary conditions (asopposed to the general conditions).From now on, we will use the subscript notation, so theFibonacci numbers


View Full Document

UNL CSCE 235 - Recursion

Documents in this Course
Logic

Logic

77 pages

Proofs

Proofs

82 pages

Induction

Induction

85 pages

Proofs

Proofs

52 pages

Sets

Sets

8 pages

Recursion

Recursion

16 pages

Proofs

Proofs

82 pages

Functions

Functions

71 pages

Recursion

Recursion

50 pages

Functions

Functions

54 pages

Graphs

Graphs

56 pages

Induction

Induction

32 pages

Relations

Relations

60 pages

Graphs

Graphs

10 pages

Recursion

Recursion

80 pages

Functions

Functions

16 pages

Recursion

Recursion

16 pages

Sets

Sets

52 pages

Relations

Relations

60 pages

Load more
Download Recursion
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recursion and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recursion 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?