# Category Archives: Recursion

Posts that are related to Recursion.

## Sum of natural numbers using recursion

Given a number n, find sum of first n natural numbers. To calculate the sum, we will use a recursive function recur_sum(). Examples : Input… Read More »

## Program to find the minimum (or maximum) element of an array

Given an array, write functions to find minimum and maximum elements in it. Output: Minimum element of array: 1 Maximum element of array: 1234 Time… Read More »

## Recursive insertion and traversal linked list

We have discussed different methods of linked list insertion. How to recursively create a linked list? Recursively inserting at the end: To create a Linked… Read More »

## Recursive function to delete k-th node from linked list

Given a singly linked list delete node at k-th position without using loop. Examples: Input : list = 9->8->3->5->2->1 k = 4 Output : 9->8->3->2->1… Read More »

## Alexander Bogomolny’s UnOrdered Permutation Algorithm

The Alexander Bogomolyn’s algorithm is used to permute first N natural numbers. Given the value of N we have to output all the permutations of… Read More »

## Combinations in a String of Digits

Given an input string of numbers, find all combinations of numbers that can be formed using digits in the same order. Examples: Input : 123… Read More »

## Minimum tiles of sizes in powers of two to cover whole area

Given an area of N X M. You have infinite number of tiles of size 2i X 2i, where i = 0, 1, 2,… so… Read More »

## Generate all passwords from given character set

Given a set of characters generate all possible passwords from them. This means we should generate all possible permutations of words using the given characters,… Read More »

## Print N-bit binary numbers having more 1’s than 0’s in all prefixes

Given a positive integer n, print all n-bit binary numbers having more 1’s than 0’s for any prefix of the number. Examples: Input : n… Read More »

## Print all leaf nodes of a Binary Tree from left to right

Given a binary tree, we need to write a program to print all leaf nodes of the given binary tree from left to right. That… Read More »

## Recursive Tower of Hanoi using 4 pegs / rods

Tower of Hanoi is a mathematical puzzle. Traditionally, It consists of three poles and a number of disks of different sizes which can slide onto… Read More »

## Find m-th summation of first n natural numbers.

m-th summation of first n natural numbers is defined as following. If m > 1 SUM(n, m) = SUM(SUM(n, m – 1), 1) Else SUM(n,… Read More »

## All possible binary numbers of length n with equal sum in both halves

Given a number n, we need to print all n-digit binary numbers with equal sum in left and right halves. If n is odd, then… Read More »

## Check if a destination is reachable from source with two movements allowed

Given coordinates of a source point (x1, y1) determine if it is possible to reach the destination point (x2, y2). From any point (x, y)… Read More »

## Recursive solution to count substrings with same first and last characters

We are given a string S, we need to find count of all contiguous substrings starting and ending with same character. Examples : Input :… Read More »