← Time & Space Complexity Quiz: all 8 questions
Time & Space Complexity Quiz · Question 7 of 8
What is the extra space complexity of this recursive function? (code)
What is the extra space complexity of this recursive function?
def count_down(n):
if n == 0:
return
count_down(n - 1)
- A.O(1)
- B.O(n)
- C.O(log n)
- D.O(n²)
Answer & explanation
Correct answer: O(n)
Each call waits on the call stack until the base case — n calls deep means O(n) space.
Can you get the rest right without peeking?
Take the timed Time & Space Complexity Quiz quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →