Skip to main content

Posts

Showing posts with the label The Crazy Programmer Types of Recursion With Examples Types of Recursion With Examples The Crazy Programmer

Types of Recursion With Examples Vijay Sinha The Crazy Programmer

In this article, we will look into the different types of Recursion generally seen in programming to solve various problems. We will look at description of each type with example through code for better understanding. First of all, let’s have a quick recap of Recursion. In general, Recursion is an approach to solve problems where the solution depends on the solutions of smaller instances or sub-problems of the same problem. So, in Programming A function that calls itself repeatedly (can be one time call) is called a Recursive Function . Types of Recursion Recursion or Recursive Functions in programming paradigm can be classified mainly into 2 types: Direct Recursion Indirect Recursion Let us look at each type and their examples: Direct Recursion Direct Recursion occurs when a function explicitly calls the same function again. This is the simplest form of recursion. This is again subdivided into 3 types: 1. Tail Recursion Tail Recursion occurs if a recursive function calls