Recursion
Base case formula:
(How much work is done with a problem size of 0?)
Recursive equations include:
-> Base case -> recursive case
Differences between it and recursion
-iteration uses same activation record: recursive doesn't.
Tail Recursion
1. Base Case 2. Recursive case. 3. Recursive call.
Explicit BaseCase:
A specific base-case.
Implicit Base-case
An implied base case -usually occurs in an if, then statement. It beats around the bush. That mofo.
Iteration:: stopping statement is equivalent to the recursion's:
Base case
Recursion and iteration similarity:
Both return 1+ statements until a condition is met
What will infinent recursion result in?
Call stack overflow
Two parts of the memory:
Call stack::Heap
How to make the equation:
Derive it from the formula:
Goal of recursion:
Divide a problem into smaller/smaller problems of the same kind until the problem is so small that it has an obvious solution
Rule 2:
Each recursive method makes progress toward the base case
Recursion statements with more than one return statement:
Each selection will select one of the 2+ paths. Thereby, the end-result will, essentially, be the same.
Rule 1:
Every recursive equation has a base case: or else it results in an infinite loop
does recursion take less memory?
Exno
Recursive Case formula:
How much work is done in the recursive case when the problem size is 0 + (time for N-1)
How to make a table>
Left side: N... right side.. formula with N
The iteration's body is equivalent to the recursion's:
Recursive case:
Recursive case formula specifics:
T(N) = (amount of time OUTSIDE OF RECURSIVE CALL) + (Total number of recursive calls) * T(Problem size passed into recursive call)
Base Case
The condition by which the recursion stops (no recursive case is made). The simplest case condition for the recursion.
Recursive case:
This is the line of code that includes what the recursion is supposed to do in each iteration along with the next recursive call
Problem size for recursive formula:
if, in each problem size, it decreases by 1, it will be T(n-1)
Is recursion faster?
no
what kind of recursion is better implemented in a looP?
tail recursion