{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

COP3502_18_RecurrenceRelations

# COP3502_18_RecurrenceRelations - Recurrence Relations...

This preview shows pages 1–9. Sign up to view the full content.

Computer Science Department University of Central Florida Recurrence Relations COP 3502 – Computer Science I

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Recurrence Relations page 2 Outline Recursion Simple warm up example (Factorial n) Recurrence Relations Factorial N Power N
Recurrence Relations page 3 Recursion What is Recursion? Powerful, problem-solving strategy Solves large problems by reducing them to smaller problems of the same form Example: Compute Factorial of a Number 4! = 4 * 3 * 2 * 1 = 24 n! = n * (n-1) * (n-2) * … * 2 * 1 Also, 0! = 1 (just accept it!)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Recurrence Relations page 4 Recursion Example: Compute Factorial of a Number Recursive Solution Note that each factorial is related to a factorial of the next smaller integer n! = n * (n-1)! 4! = 4 * (4-1)! = 4 * (3!) But we need something else We need a stopping case, or this will just go on and on and on NOT good! We let 0! = 1 So in “math terms”, we say n! = 1 if n = 0 n! = n * (n-1)! if n > 0
Recurrence Relations page 5 Recursion Example: Compute Factorial of a Number Recursive Solution --- in C code int fact (int n) { if (n = 0) return 1; else return (n * fact(n-1)); } This is recursive. Why? It defines the factorial of n in terms of the factorial of And notice how this function is very clean and basically follows the mathematical definition of factorial.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Recurrence Relations page 6 Recurrence Relations Today we go over Recurrence Relations The Question: What is a recurrence relation? an equation that defines a sequence recursively each term of the sequence is defined as a function of the preceding term What is the purpose? In response, let us ask, what is the purpose using Summations in Big-O analysis? Answer: Summations are a tool to assist in measuring the running time of iterative algorithms
Recurrence Relations page 7 Recurrence Relations Today we go over Recurrence Relations What is the purpose? But can we use this same method of analysis, along with summations, to decipher the running time of recursive algorithms? You cannot! You cannot simply “eyeball” a recursive function for a minute or two, in the way you can an iterative function, and come up with a Big-O. Just doesn’t work. So just like summations are a tool to help find the Big-O of iterative algorithms Recurrence Relations are a tool to help find the Big-O of recursive algorithms

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Recurrence Relations page 8 Recurrence Relations Back to Factorial N… int fact (int n) { if (n = 0) return 1; else return (n * fact(n-1)); } The GOAL: We want to come up with an equation that properly expresses this fact function in a recursive manner . Then we will need to solve this newly found equation. We do so by putting it into its “closed form”.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 46

COP3502_18_RecurrenceRelations - Recurrence Relations...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online