# Category Archives: Recursion

Given an integer, write a function that returns true if the given number is palindrome, else false. For example, 12321 is palindrome, but 1451 is… Read More
There are some glasses with equal capacity as 1 litre. The glasses are kept as follows:   1 2 3 4 5 6 7 8 9… Read More
Following is a C++ program that prints 1 to 100 without loop and without recursion. #include <iostream> using namespace std;    template<int N> class PrintOneToN… Read More
In computer science and mathematics, the Josephus Problem (or Josephus permutation) is a theoretical problem. Following is the problem statement:There are n people standing in… Read More
Question 1 Predict the output of the following program. What does the following fun() do in general?   C++ #include <iostream> using namespace std;   int… Read More
Question 1 Consider the following recursive C function. Let len be the length of the string s and num be the number of characters printed on… Read More
Question 1Predict the output of following program. What does the following fun() do in general?   C++ #include <iostream> using namespace std; int fun(int a, int… Read More
Recursion:In programming terms a recursive function can be defined as a routine that calls itself directly or indirectly.Using recursive algorithm, certain problems can be solved… Read More
Question 1 Predict the output of following program.  C++ #include <iostream> using namespace std;   void fun(int x) {     if(x > 0)     {         fun(--x);         cout <<… Read More
Explain the functionality of below recursive functions.  Question 1  C++ void fun1(int n) {    int i = 0;      if (n > 1)      fun1(n - 1);… Read More
Explain the functionality of following functions.  Question 1  C++ /* Assume that n is greater than or equal to 1 */ int fun1(int n) {… Read More
Explain the functionality of the following functions.  Question 1  C++ int fun1(int x, int y) {     if (x == 0)         return y;     else         return fun1(x… Read More
Write a program to reverse a stack using recursion. You are not allowed to use loop constructs like while, for..etc, and you can only use… Read More
Assume the structure of a Linked List node is as follows.   C struct Node {   int data;   struct Node *next; }; Python3 class Node:     def… Read More
Write a function to print spiral order traversal of a tree. For below tree, function should print 1, 2, 3, 4, 5, 6, 7.    … Read More