Recursion: Conceptual
Recursion gives you a new perspective on problem-solving by defining a problem in terms of itself.
StartKey Concepts
Review core concepts you need to learn to master this subject
Base Case of a Recursive Function
Recursive Step in Recursive Function
What is Recursion
Call Stack in Recursive Function
Big-O Runtime for Recursive Functions
Weak Base Case in Recursive Function
Execution Context of a Recursive Function
Base Case of a Recursive Function
Base Case of a Recursive Function
function countdown(value)
if value is negative or zero
print "done"
otherwise if value is greater than zero
print value
call countdown with (value-1)
A recursive function should have a base case with a condition that stops the function from recursing indefinitely. In the example, the base case is a condition evaluating a negative or zero value to be true.
- 1You’ve heard about a trendy new spot that sells fruit sandwiches. What are fruit sandwiches? You have no idea, but you’re eager to find out! Sadly, when you arrive at the store, the line is out t…
- 2Recursion is a strategy for solving problems by defining the problem in terms of itself. For example, to sum the elements of a list we would take the first element and add it to the **sum of t…
- 3A recursive approach requires the function invoking itself with different arguments. How does the computer keep track of the various arguments and different function invocations if it’s the sa…
- 4Recursion has two fundamental aspects: the base case and the recursive step. When using iteration, we rely on a counting variable and a boolean condition. For example, when iterating through the …
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory