Week 11: Recursion / Command Line Parameters / UNIX Flashcards
What is recursion?
Defining something in terms of itself
Recursive definitions MUST include
A base case
In recursion, the base case is also known as the
Simplest case
In recursion, the recursive part is also known as the
General case
Why is a base case needed in recursion?
Recursive definitions without a base case will run infinitely
Recursion can be an alternative to
Iteration
A function that makes use of recursion is called
A recursive method
What does a recursive method for defining a factorial look like?
The base case is that the number being tested is 1
With recursion, what happens with the memory?
Every time the recursive function calls itself, it creates a new place in memory in the stack frame for the new function call
For a RECURSIVE function that calculates the factorial of a number, what is the BASE case?
if (numb == 1) {
result == 1;
}
For a RECURSIVE function that calculates the factorial of a number, what is the NON BASE case? When does it execute?
*given the function is called SumRec()*
else {
result = (numb + SumRec( numb - 1));
}
This executes when numb is not equal to 1
For a recursive function , how many copies of the code are there?
Just one, like any other function
When does the recursive function stop calling itself?
When the base case is reached
What happens when the base case is finally reached?
One after one, the function returns by popping off the runtime stack to the calling function until we get to the first call of the function.
The most important function of C is ____ function. It is mostly defined with a return type of _____ and without _____
The most important function of C is main() function. It is mostly defined with a return type of int and without parameters