Here are 20 recursion exercises in algorithms, inspired by the structure in the PDF you
provided:
Exercise 1
Write a recursive function Sum(N) that computes the sum of all integers from 1 to N.
Exercise 2
Propose a recursive function Factorial(N) to compute the factorial of a given number N.
Exercise 3
Write a recursive function Power(base, exp) that calculates base raised to the power of exp.
Exercise 4
Develop a recursive function Fibonacci(n) that returns the nth Fibonacci number.
Exercise 5
Write a recursive function GCD(A, B) to find the greatest common divisor of two numbers A
and B.
Exercise 6
Create a recursive function CountDigits(N) that returns the number of digits in a given
integer N.
Exercise 7
Write a recursive function ReverseString(S) to reverse a given string S.
Exercise 8
Propose a recursive function IsPalindrome(S) that checks whether a string S is a
palindrome.
Exercise 9
Develop a recursive function MaxInArray(arr, N) that returns the maximum element in an
array of size N.
Exercise 10
Write a recursive function BinarySearch(arr, left, right, target) to perform a binary
search for a target value in a sorted array.
Exercise 11
Propose a recursive function MergeSort(arr) that sorts an array using merge sort.
Exercise 12
Create a recursive function TowerOfHanoi(N, source, destination, auxiliary) to
solve the Tower of Hanoi problem for N disks.
Exercise 13
Write a recursive function CountWays(steps) to calculate the number of ways to climb a
staircase with steps steps, where you can take 1 or 2 steps at a time.
Exercise 14
Propose a recursive function PrintAllSubsets(arr) that prints all subsets of a given array.
Exercise 15
Write a recursive function Permutations(arr, left, right) that generates all
permutations of a given array.
Exercise 16
Develop a recursive function SubsetSum(arr, target) to determine if there is a subset of
arr whose sum equals the target.
Exercise 17
Create a recursive function SumOfDigits(N) that computes the sum of the digits of an integer
N.
Exercise 18
Propose a recursive function IsPrime(N, i) that checks if a number N is prime using
recursion.
Exercise 19
Write a recursive function NQueens(N) to solve the N-Queens problem.
Exercise 20
Propose a recursive function FindPaths(maze, x, y) to find all possible paths in a maze
from the top-left corner to the bottom-right corner.