In a recursive function, what is the base case?
The simple case solved directly, without calling itself again, so the recursion stops.
- The first line of the function
- The case answered without another recursive call ✔
- The biggest input it can handle
Why: A recursive function solves a big problem by calling itself on a smaller one. The base case, like a list of one item already being sorted, is where it stops shrinking and just answers.
Huh, didn't know that: Merge sort's base case is a list of one item, which is already sorted by definition.
To understand recursion, you must first understand recursion.
References
Answer: The case answered without another recursive call. A recursive function solves a big problem by calling itself on a smaller one. The base case, like a list of one item already being sorted, is where it stops shrinking and just answers.
- MIT 6.006 Introduction to Algorithms, Lecture 3: Sorting ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/resources/mit6_006s20_lec3
Base case: for n = 1, array has one element so is sorted
Checked 2026-10-10.
Think this answer is wrong? Tap "Challenge this answer" on the card in the game and tell us why.
More stuff everyone should know
That's stuff everyone should know.