Answer the question

Answer the question

by Md Assaduzzaman -
Number of replies: 23

what is recursion and What is the base condition in recursion?

In reply to Md Assaduzzaman

Re: Answer the question

by Al-Amin Khan -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques
In reply to Md Assaduzzaman

Re: Answer the question

by Mohammed Intisher Islam -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques.
In reply to Md Assaduzzaman

Re: Answer the question

by Abdus Sami -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques
In reply to Md Assaduzzaman

Re: Answer the question

by Maliha Benta Mobarak -
When Function call itself called recursion and for those conditions the recursion function stop called base conditions
In reply to Md Assaduzzaman

Re: Answer the question

by Ali Jahan Riashad -
Recursion is a method in C++ which calls itself directly or indirectly until a suitable condition is met. In this method, we repeatedly call the function within the same function, and it has a base case and a recursive condition.
In reply to Md Assaduzzaman

Re: Answer the question

by Ankur Saha -
Recursion is a programming technique where a function calls itself to solve a problem. It breaks down a complex problem into smaller, more manageable subproblems, allowing the function to solve each part incrementally.

A base condition (or base case) is a crucial part of recursion. It defines the stopping criteria for the recursive calls. Without a base condition, a recursive function would continue to call itself indefinitely, leading to a stack overflow. The base condition typically handles the simplest cases of the problem, where the solution is straightforward and does not require further recursion.

### Example

Here’s a classic example using the factorial function:

1. **Recursive Case**: \( \text{factorial}(n) = n \times \text{factorial}(n-1) \) for \( n > 1 \)
2. **Base Condition**: \( \text{factorial}(1) = 1 \)

In this example, the recursion continues until it reaches the base condition, ensuring that the function eventually stops calling itself.
In reply to Md Assaduzzaman

Re: Answer the question

by shovon das -
Recursion is a programming technique in which a function calls itself to solve smaller instances of a problem until it reaches a base condition. It’s commonly used for tasks that can be broken down into simpler, similar subtasks, like calculating factorials, traversing data structures, or solving puzzles like the Tower of Hanoi.
In reply to Md Assaduzzaman

Re: Answer the question

by Md. Tanvir Islam -
Recursion is a programming technique where a function calls itself to solve a problem. It typically involves breaking a problem down into smaller, more manageable subproblems. Each recursive call works on a smaller portion of the original problem until it reaches a base case, which is a simple instance of the problem that can be solved directly without further recursion.
In reply to Md Assaduzzaman

Re: Answer the question

by Arafat Islam -
The recursion process in C refers to the process in which the program repeats a certain section of code in a similar way. Thus, in the programming languages, when the program allows the user to call any function inside the very same function, it is referred to as a recursive call in that function.
In reply to Md Assaduzzaman

Re: Answer the question

by Md Ikramul Islam Sami -
Recursion is a programming and mathematical concept where a function calls itself in order to solve a problem. It typically breaks a problem down into smaller, more manageable sub-problems. A recursive function generally has two main components:

1. **Base Case**: A condition under which the function returns a value without making a recursive call, preventing infinite loops.
2. **Recursive Case**: The part of the function where it calls itself with modified arguments to approach the base case.

For example, calculating the factorial of a number \( n \) can be defined recursively:

- **Base Case**: \( \text{factorial}(0) = 1 \)
- **Recursive Case**: \( \text{factorial}(n) = n \times \text{factorial}(n-1) \) for \( n > 0 \)

Recursion can simplify code and make it more elegant, but it can also lead to performance issues if not implemented carefully, particularly with deep recursion leading to stack overflow.
In reply to Md Assaduzzaman

Re: Answer the question

by AL MUBIN -
When Function call itself called recursive. And base conditions is for those conditions recursion function stop
In reply to Md Assaduzzaman

Re: Answer the question

by KRISTI DEBANGONA MITRA -
Recursion is a process where a function calls itself to solve a problem. The *base condition* is the stopping point that prevents infinite recursion by providing a direct answer without further calls.
In reply to Md Assaduzzaman

Re: Answer the question

by Abdur Rouf Rokon -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques.When Function call itself called recursive. And base conditions is for those conditions recursion function stop.

Recursion is a method in C++ which calls itself directly or indirectly until a suitable condition is met. In this method, we repeatedly call the function within the same function, and it has a base case and a recursive condition.
In reply to Md Assaduzzaman

Re: Answer the question

by Ahnab Shariar -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques.

Recursion is a method in C++ which calls itself directly or indirectly until a suitable condition is met. In this method, we repeatedly call the function within the same function, and it has a base case and a recursive condition.
In reply to Md Assaduzzaman

Re: Answer the question

by Jannat Rayhana Tarin -
Recursion is the process of a function calling itself repeatedly till the given condition is satisfied. The base condition specifies a scenario where the function can directly return a result without making further recursive calls.
In reply to Md Assaduzzaman

Re: Answer the question

by sharaban tohora litha -
The recursion process in C refers to the process in which the program repeats a certain section of code in a similar way.
A base case in recursive functions is a condition or scenario where the function stops calling itself and returns a result without further recursion.
In reply to Md Assaduzzaman

Re: Answer the question

by Nafis Rizone -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques
In reply to Md Assaduzzaman

Re: Answer the question

by Most Juwayriah -
Recursive Case: This is the part of the function where the function calls itself with a modified argument, moving towards a base case. This is where the main problem is divided into smaller subproblems.

Base Case: The base case is a condition that stops the recursion from continuing indefinitely. It provides a simple, non-recursive solution to the smallest subproblem. Without a base case, the function would call itself forever, leading to a stack overflow error.
In reply to Md Assaduzzaman

Re: Answer the question

by Parvez Mosharaf Siam -
A Function calling itself again and again directly or indirectly is called Recursion, and the function which it calls is called a recursive function, it is used in divide and conquer algorithms/techniques
In reply to Md Assaduzzaman

Re: Answer the question

by Md. Imran Ali Limon -
Recursion
Recursion is a programming technique where a function calls itself directly or indirectly in order to solve a problem. A recursive function typically solves a problem by breaking it down into smaller sub-problems of the same type. Each recursive call handles a simpler version of the original problem until a certain base condition is met, at which point the function stops calling itself and starts returning results.

Key Characteristics of Recursion:
Recursive Function: A function that calls itself.
Base Condition (or Base Case): The condition that stops the recursion. If the base condition is met, the function does not call itself further.
Recursive Call: The part of the function where it calls itself with a modified argument (often to solve a simpler version of the problem).
Why Use Recursion?
Recursion is particularly useful for solving problems that can be broken down into smaller, similar sub-problems. It is often used in problems like:

Factorial calculation
Fibonacci series generation
Tree and graph traversals
Divide and conquer algorithms (e.g., merge sort, quicksort)
Example of Recursion: Factorial Calculation
To calculate the factorial of a number
š‘›
n, the formula is:

š‘› !=š‘›Ć—(š‘›āˆ’1)Ɨ(š‘›āˆ’2)×⋯×1
n!=nƗ(nāˆ’1)Ɨ(nāˆ’2)×⋯×1
For example,
5 !=5Ɨ4Ɨ3Ɨ2Ɨ1=120
5!=5Ɨ4Ɨ3Ɨ2Ɨ1=120.

In recursion, we break down the problem into simpler versions:

š‘› !=š‘›Ć—(š‘›āˆ’1)!
n!=nƗ(nāˆ’1)!
Base condition: When
š‘›=1
n=1, the result is 1, and we stop.
Recursive Code for Factorial:
cpp
Copy code
#include using namespace std;

int factorial(int n) {

if (n <= 1) {
return 1;
}

else {
return n * factorial(n - 1);
}
}

int main() {
int number = 5;
cout << "Factorial of " << number << " is: " << factorial(number) << endl;
return 0;
}
In reply to Md Assaduzzaman

Re: Answer the question

by Mahfuz Al Nayem -
Recursive Case: This is the part of the function where the function calls itself with a modified argument, moving towards a base case. This is where the main problem is divided into smaller subproblems.

Base Case: The base case is a condition that stops the recursion from continuing indefinitely. It provides a simple, non-recursive solution to the smallest subproblem. Without a base case, the function would call itself forever, leading to a stack overflow error.