Feature
Feature
Each node can have any If there is n nodes then there would
Edges number of edges. be n-1 number of edges
Approach It works on the concept of FIFO It works on the concept of LIFO (Last In
used (First In First Out). First Out).
Recursion is technique used in computer science to solve big problems by breaking them into
smaller, similar problems. 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.
What is a Recursive Algorithm?
A recursive algorithm is an algorithm that uses recursion to solve a problem. Recursive
algorithms typically have two parts:
1. Base case: Which is a condition that stops the recursion.
2. Recursive case: Which is a call to the function itself with a smaller version of the problem.
Types of Recursion
There are several different recursion types and terms. These include:
Direct recursion: This is typified by the factorial implementation where the methods call
itself.
In-Direct recursion: This happens where one method, say method A, calls another
method B, which then calls method A. This involves two or more methods that eventually
create a circular call sequence.
Head recursion: The recursive call is made at the beginning of the method.
Tail recursion: The recursive call is the last statement.
Example 1: Factorial: The factorial of a number n is the product of all the integers from 1 to n.
The factorial of n can be defined recursively as:
factorial(n) = n * factorial(n-1)