Recursion
Recursion is a programming technique where a function calls itself again and again.Base case: Every recursive function uses a condition to terminate. It is known as base case. As soon as the condition for base case is true the control terminates the function otherwise, it keeps calling the function
Recursion is a programming technique where a function calls itself again and again.
Base case: Every recursive function uses a condition to terminate. It is known as base case. As soon as the condition for base case is true the control terminates the function otherwise, it keeps calling the function again and again(infinitely).
The statement that calls the function repeatedly from its block is said to be 'Recursive case'.
Advantages of recursion
* It makes the code small and clear so the program code becomes clear and easy to understand.
* Minimum number of variables are used
* The algorithm is precise, readable and efficient
*Easier to debug and obtain error free result.
Limitations of recursion
* More execution time
* It can result in stack overflow
* Occupies more space
Example code of a recursive function:
Types of recursion
1. Direct recursion (linear recursion)
In this type of recursion the function is called from within the same block.
Two categories of direct recursion are
* Tail recursion: In this type of recursion recursive call is the last statement of the function. For example factorial of a number code.
//Recursive factorial function
int fact(int n)
{
if(n==0) return 1;
else
return (n* fact(n-1));
}* Binary recursion:In this type of recursion function calls itself from two distinct points. For example GCD program code.
//Recursive GCD function
int gcd(int n1,int n2)
{
if(n1==n2)
return n1;
else
if(n1>n2)
return(gcd(n1-n2,n2));
else
return(gcd(n1,n2-n1));
}2. Indirect Recursion (Mutual Recursion):
In this type of recursion the function is called from another function block mutually. Let two functions A and B such that function B is called from function A and vice versa then this technique is called mutual recursion.
For programs related to recursion click the given link
Armstrong Number with Recursion
Binary Search
Related Posts
Continue learning with these related articles

Logic Gates for ISC Class 11: Truth Tables, Universal Gates, Half and Full Adder
ISC Class 11 Computer Science notes on logic gates: AND, OR, NOT, NAND, NOR, XOR and XNOR with truth tables, why NAND and NOR are universal gates, and half adder and full adder circuits with their Boolean expressions.
Decimal to Binary Conversion in Java: 3 Programs with Examples
How to convert a decimal number to binary on paper and in Java: three programs (String, place value and Integer.toBinaryString), binary to decimal, a dry run and common mistakes.

ISC Class 11 Computer Science Sample Paper 2026-27 with Solutions
A full 70-mark ISC Class 11 Computer Science sample paper for the 2026-27 annual exam: MCQs, number systems, propositional logic, logic gates, Java classes, arrays, strings, searching and sorting, and computing ethics, with complete worked solutions.