diff --git a/README.md b/README.md
index 6a75f508e..580aaf8ba 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,13 @@ We are grateful to all the contributors who have helped improve this project. Yo
Ananya Gupta
+
+
+
+
+ Narendra Dhangar
+
+ |
@@ -110,6 +117,8 @@ We are grateful to all the contributors who have helped improve this project. Yo
Irfan Ansari
|
+
+
@@ -117,8 +126,6 @@ We are grateful to all the contributors who have helped improve this project. Yo
Yash Kumar Saini
|
-
-
@@ -154,21 +161,14 @@ We are grateful to all the contributors who have helped improve this project. Yo
Shalini Bhandari
|
+
+
Mohith Singh
- |
-
-
-
-
-
-
- Narendra Dhangar
-
|
diff --git a/blog/authors.yml b/blog/authors.yml
index e85e5725d..248483f5f 100644
--- a/blog/authors.yml
+++ b/blog/authors.yml
@@ -13,4 +13,18 @@ ajay-dhangar:
linkedin: ajay-dhangar
github: ajay-dhangar
stackoverflow: 18530900
- newsletter: https://ajay-dhangar.github.io
\ No newline at end of file
+ newsletter: https://ajay-dhangar.github.io
+
+narendra-dhangar:
+ name: Narendra Dhangar
+ title: B.Tech (CSE) Student
+ url: https://www.instagram.com/narendra_dh._05/
+ image_url: https://github.com/narendra-dhangar.png
+ email: narendradhangar63@gmail.com
+ page: true # Turns the feature on
+ description: >
+ A dedicated Computer Science and Engineering student with a passion for problem-solving and algorithms. I am constantly exploring various fields of computer science, from data structures and algorithms to web development and machine learning. As an avid learner, I enjoy tackling challenging problems and sharing knowledge with the community. Eager to contribute to open-source projects and make an impact in the tech world.
+
+ socials:
+ linkedin: narendra-dhangar-880558297
+ github: narendra-dhangar
diff --git a/blog/mastering-recursion.md b/blog/mastering-recursion.md
new file mode 100644
index 000000000..da32478b5
--- /dev/null
+++ b/blog/mastering-recursion.md
@@ -0,0 +1,134 @@
+---
+slug: mastering-recursion
+title: 'Mastering Recursion: Concepts, Problems, and Optimization'
+authors: [narendra-dhangar]
+tags: [recursion, algorithms, dsa, optimization, narendra-dhangar]
+---
+
+Recursion is a fundamental concept in programming and problem-solving. It provides an elegant solution to many problems, yet understanding recursion requires a solid grasp of the underlying principles. In this blog, we will dive deep into the concept of recursion, explore common recursive problems, and look at techniques for optimizing recursive algorithms.
+
+
+
+## What is Recursion?
+
+Recursion is a process where a function calls itself to solve a problem. A recursive function breaks down a problem into smaller, easier-to-solve sub-problems.
+
+### Structure of a Recursive Function:
+A typical recursive function consists of two main parts:
+1. **Base Case**: The condition under which the recursion ends. Without this, the function would call itself indefinitely, leading to a stack overflow.
+2. **Recursive Case**: The part where the function calls itself to solve smaller instances of the problem.
+
+### Example of Recursion:
+Here’s a simple example of recursion, calculating the factorial of a number `n`:
+
+```javascript
+function factorial(n) {
+ if (n === 0) {
+ return 1; // Base case: factorial of 0 is 1
+ }
+ return n * factorial(n - 1); // Recursive case
+}
+```
+
+In this example, the problem of calculating the factorial is broken down into multiplying `n` by the factorial of `n - 1`, until it reaches the base case.
+
+---
+
+## Key Concepts in Recursion:
+
+1. **Base Case and Recursive Case**: These are the most critical components of any recursive function. Without a base case, your function will recurse infinitely.
+
+2. **Stack Memory**: Every time a recursive function is called, its execution is stored in the stack. When the base case is reached, the function starts returning, popping values off the stack.
+
+3. **Recursive Tree**: Visualizing recursion as a tree can help in understanding how recursive calls are executed. Each recursive call splits into further sub-calls until the base case is hit.
+
+### Common Pitfalls:
+- **Missing Base Case**: Leads to infinite recursion.
+- **Redundant Computations**: In some problems, recursive calls recompute the same values multiple times (like in the Fibonacci sequence).
+
+---
+
+## Recursion Problems:
+
+### 1. Fibonacci Series:
+
+The Fibonacci series is a classic problem to demonstrate recursion. The nth Fibonacci number is the sum of the two preceding numbers.
+
+**Recursive Fibonacci Solution**:
+
+```javascript
+function fibonacci(n) {
+ if (n <= 1) {
+ return n; // Base case
+ }
+ return fibonacci(n - 1) + fibonacci(n - 2); // Recursive case
+}
+```
+
+While this solution is intuitive, it performs redundant computations and can be very slow for larger values of `n`.
+
+---
+
+## Optimizing Recursive Algorithms:
+
+### 1. **Memoization**:
+Memoization stores the results of expensive function calls and reuses them when the same inputs occur again, reducing the time complexity of the function.
+
+**Optimized Fibonacci with Memoization**:
+
+```javascript
+function fibonacci(n, memo = {}) {
+ if (n in memo) {
+ return memo[n]; // Return stored result if available
+ }
+ if (n <= 1) {
+ return n; // Base case
+ }
+ memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo); // Recursive call with memoization
+ return memo[n];
+}
+```
+This optimized version reduces the time complexity from $O(2^n)$ to $O(n)$.
+
+### 2. **Tail Recursion**:
+Tail recursion is a specific form of recursion where the recursive call is the last thing executed by the function. Tail-recursive functions can be optimized by some compilers or interpreters to prevent stack overflow.
+
+**Tail-Recursive Factorial**:
+
+```javascript
+function tailFactorial(n, accumulator = 1) {
+ if (n === 0) {
+ return accumulator; // Base case
+ }
+ return tailFactorial(n - 1, n * accumulator); // Tail-recursive call
+}
+```
+
+### 3. **Recursion to Iteration**:
+For some problems, recursion can be replaced with iteration to avoid deep recursion, which can lead to stack overflow. Converting recursive functions to iterative ones ensures better memory management.
+
+---
+
+## Problem-Solving with Recursion:
+
+Recursion is widely used to solve various algorithmic problems, such as:
+
+1. **Binary Search**:
+ A divide-and-conquer algorithm that works efficiently by dividing the array into halves.
+
+2. **Towers of Hanoi**:
+ A mathematical problem that requires moving disks between rods under certain conditions.
+
+3. **Permutations and Combinations**:
+ Recursion is used to generate all possible arrangements of a set of items.
+
+4. **Tree Traversal**:
+ Recursion is the natural way to traverse tree structures, such as in **pre-order**, **in-order**, and **post-order** traversals.
+
+---
+
+## Conclusion:
+
+Recursion is a powerful tool in a developer's arsenal. However, it is essential to understand when and how to use it effectively. Optimizing recursive algorithms with techniques like memoization, tail recursion, or converting them into iterative solutions ensures they remain efficient even for large inputs.
+
+With practice, mastering recursion will open doors to solving complex problems in a more structured and elegant way.
|