# Category Archives: Recursion

Posts that are related to Recursion.

## Recursive insertion and traversal linked listNovember 8, 2017

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 listOctober 30, 2017

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 AlgorithmOctober 19, 2017

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 DigitsOctober 15, 2017

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 areaOctober 14, 2017

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 setOctober 9, 2017

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 prefixesOctober 4, 2017

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 rightSeptember 30, 2017

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 / rodsSeptember 19, 2017

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.September 16, 2017

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 halvesSeptember 8, 2017

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 allowedAugust 30, 2017

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 charactersAugust 29, 2017

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 »

## Count ways to express a number as sum of powersAugust 28, 2017

Given two integers x and n, we need to find number of ways to express x as sum of n-th powers of unique natural numbers.… Read More »

## Mutual Recursion with example of Hofstadter Female and Male sequencesAugust 15, 2017

Mutual recursion is a variation recursion. Two functions are called mutually recursive if the first function makes a recursive call to the second function and… Read More »