Recursion Notes
Recursion Notes
@rithik_codez
FUNCTIONS -
In coding, a function is a named block of reusable code
that performs a specific task or a series of related tasks.
Functions are designed to modularize code and promote
code reusability, making programs more organized,
efficient, and easier to maintain.
RETURN STATEMENT-
The return statement is a construct used in programming
languages to specify the value that a function should
return after its execution completes. It allows a
function to produce a result or output that can be
utilized by other parts of the program.
RECURSION STACK-
A recursion stack, also known as a call stack or execution
stack, is a data structure used by programming
languages to manage the execution of recursive function
calls. It keeps track of the sequence of function calls
and their corresponding execution contexts.
Recursion Notes
@rithik_codez
RECURSION STACK-
A recursion stack, also known as a call stack or execution
stack, is a data structure used by programming languages
to manage the execution of recursive function calls. It
keeps track of the sequence of function calls and their
corresponding execution contexts.
Recursion Notes
@rithik_codez
2) WHAT IS RECURSION?
Recursion is a programming concept where a function
calls itself to solve a problem by breaking it down into
smaller, simpler instances of the same problem. It is a
way to solve complex tasks by reducing them to smaller,
more manageable subtasks.
3) Printing first 5 natural number using recursion
the code is well explained in my youtube tutorial please
feel free to refer that.
Now, what if we want to reverse the sequence from 1 2 3
4 5 to 5 4 3 2 1, We will change only the sequence of two
lines from the above code.
In simpler terms, recursion can be thought of as a
process of self-replication or self-referencing. When a
recursive function is called, it performs some computation
and then calls itself with a modified input or state. This
process continues until a base case is reached, which is a
condition that allows the recursion to stop and the
function calls to start returning values.
Recursion Notes
@rithik_codez
4) FACTORIAL PROGRAM
The factorial of a non-negative integer n, denoted as
n!, is the product of all positive integers less
than or equal to n. For example, 5! (read as "5
factorial") is calculated as 5 x 4 x 3 x 2 x 1,
which equals 120.
Factorial can be defined recursively by the following
formula:
n! = n * (n-1)!
The program is as follows
Recursion Notes
@rithik_codez