Professional Documents
Culture Documents
Recurrence Relations: COP 3502 - Computer Science I
Recurrence Relations: COP 3502 - Computer Science I
Relations
Computer Science Department
University of Central Florida
Recurrence Relations
Factorial N
Power N
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”.
Here’s the process…
Recurrence Relations page 10
Recurrence Relations
Back to Factorial N…
int fact (int n)
{
if (n = 0)
return 1;
else
return (n * fact(n-1));
}
In techno talk:
T(n) represents the # of operations of this function
T(n) can be expressed as a sum of:
T(n-1)
and the two arithmetic operations
In techno talk:
T(n) can be expressed as a sum of:
T(n-1)
and the two arithmetic operations
T(n) = T(n-1) + 2
T(0) = 1 Meaning, we it takes constant time to simply return.
T(n-1) T(100-1)
if we assume
T(n-2) that n = 100, T(100-2)
T(n-3) we have… T(100-3)
… …
T(n-something) = T(1) T(100-99) = T(1)
WASN’T
THAT
(Let’s admit it:
that sucked!)
Recurrence Relations page 46
Daily Demotivator