COP3502_18_RecurrenceRelations

COP3502_18_RecurrenceRelations - Recurrence Relations...

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

View Full Document Right Arrow Icon
Computer Science Department University of Central Florida Recurrence Relations COP 3502 – Computer Science I
Background image of page 1

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

View Full DocumentRight Arrow Icon
Recurrence Relations page 2 Outline Recursion Simple warm up example (Factorial n) Recurrence Relations Factorial N Power N
Background image of page 2
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!)
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 09/21/2011.

Page1 / 46

COP3502_18_RecurrenceRelations - Recurrence Relations...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online