Skip to content

Tag Archives: Algorithms-Recursion

Given a number N. The task is to reduce the given number N to 1 in the minimum number of steps. You can perform any… Read More
Given a string str, print of all the combinations of a string in lexicographical order.Examples:   Input: str = "ABC" Output: A AB ABC AC ACB… Read More
Given two numbers N and K. Find the number of ways to represent N as the sum of K Fibonacci numbers. Examples:   Input : n =… Read More
Given a function gcd(a, b) to find GCD (Greatest Common Divisor) of two number. It is also known that GCD of three elements can be… Read More
Given a number num as a string and a number N. The task is to write a program which converts the given number num to… Read More
Prerequisite: Dynamic Programming | Set 5 (Edit Distance) Given two strings str1 and str2, the task is to print the all possible ways to convert ‘str1’… Read More
Given a binary tree, print the level order traversal in such a way that first two levels are printed from left to right, next two… Read More
Given a non-empty string S containing only lowercase letters, print all ‘Special Subsequences’ of S. For Instance, “ab” has the following Special Subsequences-: { “A”,… Read More
Given that a coin is tossed N times. The task is to find the total number of the sequence of tosses such that after the… Read More
Given x, k and m. Compute (xxxx…k)%m, x is in power k times. Given x is always prime and m is greater than x.  Examples: … Read More
#include<stdio.h> void crazy(int n,int a,int b) {     if (n <= 0)  return;     crazy(n-1, a, b+n);     printf("%d %d %d\n",n,a,b);     crazy(n-1, b, a+n); }    int main()… Read More
Predict the output of following program #include <stdio.h> int f(int n) {     if(n <= 1)         return 1;     if(n%2 == 0)         return f(n/2);     return f(n/2) +… Read More
What does the following function do? int fun(unsigned int n) {     if (n == 0 || n == 1)         return n;        if (n%3 !=… Read More
Output of following program? #include<stdio.h> void print(int n) {     if (n > 4000)         return;     printf("%d ", n);     print(2*n);     printf("%d ", n); }    int main()… Read More
What does fun2() do in general? int fun(int x, int y) {     if (y == 0)   return 0;     return (x + fun(x, y-1)); }   … Read More

Start Your Coding Journey Now!