Practice Questions — Recursion

Recursion:

1. Write a recursive algorithm to perform x^n.

2. Write a recursive algorithm for binary search.

3. Given a number n, print following pattern without using any loop.

Examples :

Input: n = 16
Output: 16, 11, 6, 1, -4, 1, 6, 11, 16
Input: n = 10
Output: 10, 5, 0, 5, 10

4. Given a number n, print all possible non-increasing sequences with sum equals to x.

Examples:

Input: n = 3
Output: 
1 1 1
2 1
3
Input: n = 4
Output: 1 1 1 1
        2 1 1
        2 2
        3 1
        4

5. Convert decimal to binary using recursion.

6. Write a program to print all the combinations of factors of given number n.

Examples:

Input : 16
Output :2 2 2 2 
        2 2 4 
        2 8 
        4 4 

Input : 12
Output : 2 2 3
         2 6
         3 4