Recursion

Recursion

Build strong recursion fundamentals with tree-based problem solving

18 Problems
Beginner
Watch Playlist

All Problems

18 problems
1
Print 1 to N using Recursion Intro 1
Write a recursive function to print numbers from 1 to a given integer N.
Easy
Not Attempted
Video
2
Print 1 to N using Recursion Intro 2
Write a recursive function to print numbers from 1 to a given integer N.
Easy
Not Attempted
Video
3
Print 1 to N using Recursion Intro 3
Write a recursive function to print numbers from 1 to a given integer N.
Easy
Not Attempted
Video
4
Print N to 1 using Recursion Intro 4
Write a recursive function to print numbers from a given integer N down to 1.
Easy
Not Attempted
Video
5
Height of a Binary Tree
Given a binary tree, find its height. The height of a tree is the number of nodes along the longest path from the root node down to the farthest leaf node.
Easy
Not Attempted
Video
6
Sort an Array using Recursion
Sort an array of integers in ascending order using only recursion.
Medium
Not Attempted
Video
7
Sort a Stack using Recursion
Given a stack, sort it in ascending order (with the smallest elements on top) using only recursion.
Medium
Not Attempted
Video
8
Delete Middle Element of a Stack
Given a stack, delete the middle element of the stack without using any additional data structure. If stack size is even assume mid is (size-1)/2
Medium
Not Attempted
Video
9
Reverse a Stack using Recursion
Write a program to reverse a stack using recursion. You are not allowed to use any extra space other than the internal stack space used by recursion.
Medium
Not Attempted
Video
10
K-th Symbol in Grammar
We build a table of N rows. The first row is 0. For every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10. Given N and K, find the K-th (1-indexed) symbol in the N-th row.
Medium
Not Attempted
Video
11
Tower of Hanoi
The Tower of Hanoi is a mathematical puzzle where we have three rods and N disks of different sizes. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top. The objective is to move the entire stack to another rod, obeying simple rules.
Medium
Not Attempted
Video
12
Print Subsets | Print Power Set | Print all Subsequences
Given a string, find all of its subsequences, which is also known as the power set.
Easy
Not Attempted
Video
13
Print Unique Subsets
Given a string that may contain duplicates, find all of its unique subsequences. Give any solution out of multiple solutions
Medium
Not Attempted
Video
14
Permutation with Spaces
Given a string, print all permutations of the string by putting spaces between characters. The first character remains fixed.
Easy
Not Attempted
Video
15
Permutation with Case Change
Given a string, find all permutations by changing the case of each letter. Digits and symbols remain unchanged.
Easy
Not Attempted
Video
16
Generate all Balanced Parentheses
Given an integer N, generate all combinations of N pairs of well-formed (balanced) parentheses.
Medium
Not Attempted
Video
17
Print N-bit binary numbers having more 1s than 0s
Given a positive integer N, generate all N-digit binary numbers such that for any prefix of the number, the count of 1s is greater than or equal to the count of 0s.
Medium
Not Attempted
Video
18
Josephus Problem
There are N people standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people K are skipped and the next person is executed. The elimination proceeds around the circle, which is shrinking in size, until only the last person remains. Find the position of the last person.
Medium
Not Attempted
Video