🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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)
  1. A.O(1)
  2. B.O(n)
  3. C.O(log n)
  4. 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 →