LearnFrenzy
Sign in Take a free test

Recursion · Exercise 4 of 4

Recursion Recursion Coding Problems

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Classic recursive programs asked in practicals and coding interviews. Write each one yourself first, then open the solution – every solution was run on Python 3, the output shown is the real output, and Run opens it in the online Python compiler.

Question 1 Easy

Write a recursive and an iterative factorial and confirm they agree for 0 to 10.

Question page & discussion
Question 2 Medium

Write fib(n) with an explicit memo dictionary and print the first 15 terms and fib(100).

Question page & discussion
Question 3 Medium

Print all permutations of a string without duplicates (the string may repeat letters), in sorted order.

Question page & discussion
Question 4 Medium

Search a sorted list recursively and report the index found and how many comparisons were needed.

Question page & discussion
Question 5 Medium

Flatten a list nested to any depth, and count the items at each depth.

Question page & discussion
Question 6 Medium

Generate every subset of a list, and print those whose sum equals a target.

Question page & discussion
Question 7 Easy

Repeatedly sum the digits of a number until one digit remains (its digital root), and compare with the 1 + (n − 1) % 9 formula.

Question page & discussion
Question 8 Easy

Check palindromes recursively, ignoring case, spaces and punctuation.

Question page & discussion
Question 9 Hard

Count the ways to climb n stairs taking 1, 2 or 3 steps at a time, using recursion with lru_cache, for n = 1 to 10 and n = 50.

Question page & discussion
Question 10 Hard

Implement merge sort recursively using index pointers (no pop(0)) and count how many merge steps it performs.

Question page & discussion
All exercises doneBack to RecursionRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links