🌀Java Recursion Programs
Recursion solves a problem by solving smaller copies of itself until a base case stops the descent. Start with factorial and Fibonacci to see the pattern, then move on to backtracking problems such as permutations and N-Queens.25 programs · each with full code, output and a step-by-step explanation
Most Asked in Interviews
Adds up every element of an array by recursing one index at a time.
View Program →Checks whether a string is a palindrome by recursively narrowing the comparison window from both ends.
View Program →Computes n! using tail recursion, carrying the running product as an accumulator.
View Program →Computes n! using recursion.
View Program →Finds the largest element of an array by comparing it against the recursive maximum of the rest.
View Program →Finds the smallest element of an array by comparing it against the recursive minimum of the rest.
View Program →Finds the greatest common divisor of two numbers using a recursive function.
View Program →Prints every element of an array using recursive calls instead of a loop.
View Program →Prints every number from n down to 1 using a recursive function instead of a loop.
View Program →Prints every number from 1 up to n using a recursive function instead of a loop.
View Program →Prints every character of a string on its own line using recursion instead of a loop.
View Program →Reverses the digits of a number by carrying the result through recursive calls.
View Program →Adds up every number from 1 to n using a recursive function instead of a loop.
View Program →Generates the first n Fibonacci numbers recursively.
View Program →Computes the single Fibonacci number at a given position using plain recursion.
View Program →Prints every combination of a fixed size chosen from a small set of items.
View Program →Prints every possible ordering of a string's characters using backtracking.
View Program →Builds every subsequence of a string by branching into an include/exclude decision at each character.
View Program →Prints every possible subset of an array, including the empty set and the full set, using recursion.
View Program →Sorts an array by recursing once per bubble-sort pass instead of looping.
View Program →Sorts an array by recursively sorting everything before the last element, then inserting it.
View Program →Solves the classic Tower of Hanoi puzzle and prints every move.
View Program →Counts how many ways n queens can be placed on an n by n board with none attacking each other.
View Program →Finds a path from the top-left to the bottom-right of a grid, moving only through open cells.
View Program →Fills in a partially-completed 9 by 9 Sudoku grid using backtracking.
View Program →