Recursion
LockedLesson 21 of 60 · Syntax · Medium
Finish these first:Functions →Or pass the tests below to unlock it now.
The big idea
A recursive function solves a problem by calling itself on a smaller input, with a base case to stop. Python limits depth (~1000); convert deep recursion to loops or use memoization (functools.lrucache).
Think of it like this: Think of syntax and expressions like labeled measuring cups in a kitchen: each cup holds a specific kind of ingredient, and operators combine them into a new measurement.
Read the lesson
A recursive function solves a problem by calling itself on a smaller input, with a base case to stop.
def fact(n):
return 1 if n <= 1 else n * fact(n - 1)
Python limits depth (~1000); convert deep recursion to loops or use memoization (functools.lru_cache).
Quick check
Before writing code: What should `power_set_size(0)` return when your implementation of Recursion is working?
Your challenge
Write power_set_size(n) -> 2**n recursively (no **).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to java.recursion (95% overlap). Same idea; neither optimizes tail calls.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Recursion.
Learn this first
- FunctionsNot yet