DSA and problem solving

Stage 1 · Lesson 4 of 6

Space complexity and the call stack

Complexity and Big-O

is the extra memory an algorithm needs as its input grows. The input itself does not count. A few variables are O(1).

A copy of the array, a holding every item, or an output list are O(n). Recursion is the part people forget. Every call that has not finished yet keeps a small record, called a , on the call stack.

So recursion that goes n levels deep uses O(n) memory, even if it creates nothing. On large inputs it can crash with a , which means the call stack ran out of room. Balanced recursion, like or a search down a balanced tree, only goes about log n levels deep.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking Algorithm Complexity and Big-O

    Design Gurus · Beginner · Subscription

    Short course on exactly this stage, including the amortised and space cases people miss

  • CourseFree
    Algorithms, Part I

    Princeton University · Intermediate

    Free: the Analysis of Algorithms module measures real Java programs, then models their cost

Keep handy

Also worth your time

Mark this stage as not done?