# Tag Archives: Algorithms-Recursion

## Print the nodes of Binary Tree having a grandchild

Given a Binary Tree, the task is to print the nodes that have grandchildren. Examples: Input: Output: 20 8 Explanation: 20 and 8 are the… Read More »

## Check if it is possible to reach to the index with value K when start index is given

Given an array arr[] of N positive integers and two positive integers S and K, the task is to reach the position of the array… Read More »

## Count number of ways to convert string S to T by performing K cyclic shifts

Given two strings S and T and a number K, the task is to count the number of ways to convert string S to string… Read More »

## Number of ways to color N-K blocks using given operation

Given N blocks out of which K are colored. These K colored blocks are denoted by an array arr[]. The task is to count the… Read More »

## Program to find all Factors of a Number using recursion

Given a number N, the task is to print all the factors of N using recursion. Examples: Input: N = 16 Output: 1 2 4… Read More »

## Finding the lexicographically smallest diameter in a binary tree

Given a binary tree where node values are lowercase alphabets, the task is to find the lexicographically smallest diameter. Diameter is the longest path between… Read More »

## Bottom View of a Binary Tree using Recursion

Given a binary tree, the task is to find the bottom view of a binary tree using recursion. Examples: Input: 1 \ 2 \ 4… Read More »

## Find F(n) when F(i) and F(j) of a sequence are given

Given five integers i, Fi, j, Fj and N. Where Fi and Fj are the ith and jth term of a sequence which follows the… Read More »

## Recursion in Java

What is Recursion? The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called as recursive… Read More »

## Find maximum product of digits among numbers less than or equal to N

Given an integer N > 0, the task is to find the maximum product of digits among numbers less than or equal to N. Examples:… Read More »

## Recursion in Perl

Recursion is a mechanism when a function calls itself again and again till the required condition is met. When the function call statement is written… Read More »

## Program to unfold a folded linked list

A linked list L0 -> L1 -> L2 -> ….. -> LN can be folded as L0 -> LN -> L1 -> LN – 1… Read More »

## Zig-Zag traversal of a Binary Tree using Recursion

Given a Binary Tree, the task is to print the zigzag order of the tree. Examples: Input : 7 / \ 6 5 / /… Read More »

## Generate a random permutation of elements from range [L, R] (Divide and Conquer)

Given a range [L, R] where L ≤ R, the task is to generate a random permutation of the sequence [L, L + 1, L… Read More »

## Difference between Recursion and Iteration

A program is called recursive when an entity calls itself. A program is call iterative when there is a loop (or repetition). Example: Program to… Read More »