Posts that are related to Recursion.

Print all subsequences of a string using ArrayList

Given a string str, the task is to print all the sub-sequences of str. A subsequence is a sequence that can be derived from another… Read More »

Recursive Program for Binary to Decimal

Given a binary number as string, find its decimal equivalent. Examples: Input : binary = “101” Output : 5 Input : binary = “1111” Output… Read More »

Recursive program to insert a star between pair of identical characters

Given a string with repeated characters, we have to insert a star i.e.” * “ between pair of adjacent identical characters using recursion. Examples: Input… Read More »

Count of Numbers in a Range divisible by m and having digit d in even positions

Given a range represented by two positive integers l and r and two integers d and m. Find the count of numbers lying in the… Read More »

Algorithms | Recurrences | Set 1

Question 1: Which of the following is the value of T3(n) where T3(n) is defined as T3(n) = 5*T3(n-1) – 4*T3(n-2) C1*5n + C2*4n C1… Read More »

Print all paths from top left to bottom right in a matrix with four moves allowed

The problem is to print all the possible paths from top left to bottom right of an mXn matrix with the constraints that from each… Read More »

Ways to fill N positions using M colors such that there are exactly K pairs of adjacent different colors

Given three integers N, M and K. The task is to find the number of ways to fill N positions using M colors such that… Read More »

Recursive program to print all subsets with given sum

Given an array and a number, print all subsets with sum equal to given the sum. Examples: Input : arr[] = {2, 5, 8, 4,… Read More »

Count all Grandparent-Parent-Child Triplets in a binary tree whose sum is greater than X

Given an integer X and a binary tree, the task is to count the number of triplet triplets of nodes such that their sum is… Read More »

Longest Ordered Subsequence of Vowels

Given a string consisting of only vowels, find the longest subsequence in the given string such that it consists of all five vowels and is… Read More »

Number of Binary Strings of length N with K adjacent Set Bits

Given and . The task is to find the number of binary strings of length n out of 2n such that they satisfy f(bit string)… Read More »

Check if item can be measured using a scale and some weights

Given some weights of masses a0, a1, a2, …, a100, a being an integer, and a weighing scale where weights can be put on both… Read More »

Number of Paths of Weight W in a K-ary tree

Given a K-ary tree, where each node is having K children and each edge has some weight. All the edges i.e. K, that goes from… Read More »

Number of balanced bracket expressions that can be formed from a string

Given a string str comprising of characters (, ), {, }, [, ] and ?. The task is to find the total number of balanced… Read More »

Check if N can be represented as sum of integers chosen from set {A, B}

Given three integers N, A and B, the task is to find whether N can be represented as sum of A’s and B’s. Examples: Input:… Read More »