Direct Recursion

Direct recursion occurs when a function directly calls itself within the same function. Direct Recursion can be further categorized into four types:

Tail Recursion

If a recursive function calling itself and that recursive call is the last statement in the function then it’s known as Tail Recursion. After that call the recursive function performs nothing. The function has to process or perform any operation at the time of calling and it does nothing at returning time.

Tail Recursion

Time Complexity For Tail Recursion : O(n) 
Space Complexity For Tail Recursion : O(n)

Head Recursion

If a recursive function calling itself and that recursive call is the first statement in the function then it’s known as Head Recursion. There’s no statement, no operation before the call. The function doesn’t have to process or perform any operation at the time of calling and all operations are done at returning time.

Head Recursion

Time Complexity For Head Recursion: O(n) 
Space Complexity For Head Recursion: O(n)

Tree Recursion:

To understand Tree Recursion let’s first understand Linear Recursion. If a recursive function calling itself for one time then it’s known as Linear Recursion. Otherwise if a recursive function calling itself for more than one time then it’s known as Tree Recursion.

Time Complexity For Tree Recursion: O(2^n) 
Space Complexity For Tree Recursion: O(n)

Nested Recursion:

In this recursion, a recursive function will pass the parameter as a recursive call. That means “recursion inside recursion”. Let see the example to understand this recursion.

Recursion Notes for GATE Exam [2024]

This Recursion Notes for the GATE Exam provides a comprehensive guide to one of the fundamental concepts in computer science, recursion, specifically tailored for those preparing for the Graduate Aptitude Test in Engineering (GATE). Recursion is a powerful problem-solving technique where a function calls itself during its execution, and it plays a significant role in algorithm design and programming.

Table of Content

  • Introduction to Recursion
  • Need of Recursion
  • Types of Recursion
  • Direct Recursion
  • Indirect Recursion
  • Gate Previous Year Problems on Recursion

Similar Reads

Introduction to Recursion

The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function. Using a recursive algorithm, certain problems can be solved quite easily. Examples of such problems are Towers of Hanoi (TOH), Inorder/Preorder/Postorder Tree Traversals, DFS of Graph, etc. A recursive function solves a particular problem by calling a copy of itself and solving smaller subproblems of the original problems....

Need of Recursion

Recursion is an amazing technique with the help of which we can reduce the length of our code and make it easier to read and write. It has certain advantages over the iteration technique which will be discussed later. A task that can be defined with its similar subtask, recursion is one of the best solutions for it. For example; The Factorial of a number....

Types of Recursion

Recursion are mainly of two types depending on whether a function calls itself from within itself or more than one function call one another mutually. The first one is called direct recursion and another one is called indirect recursion. Thus, the two types of recursion are:...

Direct Recursion

Direct recursion occurs when a function directly calls itself within the same function. Direct Recursion can be further categorized into four types:...

Indirect Recursion

In this recursion, there may be more than one functions and they are calling one another in a circular manner....

Gate Previous Year Problems on Recursion

Question 1: In the C language: [GATE 2002: 2 marks]...