Introduction |
The Journey |
Recursion - A Formal Look |
But Won't It Go On Forever? |
The Jokes :D |
How Can Recursion Be Helpful? |
The End |
Chapter 1 of 7
Chapter 2 of 7
Chapter 3 of 7
A function whose definition includes making a call to itself, is called a recursive function.As you can see, the definition of a function named 'Calculate' is given above. The definition includes a set of commands that must be executed when the function is called. What you can also see is that one of those commands is the function itself. Thus Calculate will be called a recursive function and the process of executing it would be called recursion.
Chapter 4 of 7
JOURNEY(0) was simply 0. This case of d=0 was simple and evident enough with a known answer, that we could just stop the recursion chain there. This was the base case for the JOURNEY function.
Thus a Base Case is a case in the execution of a recursive function, where the answer of the function call does not require any more recursive calls, but instead the answer is already known or very simple to calculate.
The base case is written inside the definition of the function, specifying clearly that when the base case is reached a known answer should be returned & the recursive function call (which is also a part of the definition) should be bypassed.When defining the function in code format, an 'if-statement' is usually used to decide whether the base case has been reached in the recursion chain.
Chapter 5 of 7
Chapter 6 of 7
When given a problem to solve, can we find a recursive approach to solve the problem because it would be simpler to code.
That is, can we represent the problem as a recursive function which involves a smaller version of the same problem.
factorial( n ) = 1 * 2 * 3 * 4 * 5 . . . * n
Chapter 7 of 7