GCGrowCarrer

Recursion

Locked

Lesson 21 of 60 · Syntax · Medium

Finish these first:Functions →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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).

3

Quick check

Before writing code: What should `power_set_size(0)` return when your implementation of Recursion is working?

4

Your challenge

2 sample tests, 1 hidden

Write power_set_size(n) -> 2**n recursively (no **).

Stuck? Get a hint (free)
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.

Mastery0%