3.1.4 · D1Complexity Analysis

Foundations — Space complexity — auxiliary vs total

1,886 words9 min readBack to topic

This page builds every word, symbol, and picture the parent note Space complexity — auxiliary vs total leans on. Read top to bottom; nothing appears before it is earned.


1. What is a "memory cell"? (the atom of everything)

Before we count memory, we need to know what we're counting.

Picture a strip of labelled boxes, like lockers in a hallway. Each locker holds exactly one thing.

Figure — Space complexity — auxiliary vs total

2. The input size — the one knob we turn

The parent note writes everywhere. Here is what that letter means.


3. Two piles of memory — input vs scratch

Now the central split. Look at the picture: the box you're given, and the tray you bring out.

Figure — Space complexity — auxiliary vs total

4. "At the same time" — peak simultaneous usage

This phrase does the real work, so we slow down.

Imagine a program that opens a locker, uses it, closes it, then opens another. At no point are two open — so peak , even if it touched a million lockers across time.

Figure — Space complexity — auxiliary vs total

5. The Big-O symbol — a growth label, not a cell count

The parent writes , , , . Here is exactly what that notation says.

Read each label as a shape you can point to on a graph:

Label Plain words Picture (curve shape)
doesn't grow with a flat horizontal line
grows, but slower and slower a curve that nearly flattens
grows in step with a straight diagonal line
grows much faster a curve bending sharply up
Figure — Space complexity — auxiliary vs total

6. The recursion stack — the hidden pile

The parent calls this "the most-missed source of space." To see it, we first need the picture of what a recursive call leaves behind.

Figure — Space complexity — auxiliary vs total

7. "In-place" — the -auxiliary ideal

Picture reversing a list by swapping ends inward: you only ever hold two pointers, i and j, no matter how long the list. The list is edited where it lives. More at In-place algorithms.


Prerequisite map

Memory cell — one box one value

Peak simultaneous cells

Input size n — the knob

Growth as n rises

Big-O growth label

Counting space

Split into two piles

Input space

Auxiliary space

Recursion stack depth

Hidden auxiliary cost

In-place equals O of 1 aux

Total = input + aux

Space complexity — aux vs total


Equipment checklist

Test yourself — cover the right side, answer, then reveal.

What one physical thing does a "memory cell" correspond to?
One labelled box/locker holding exactly one value.
What does the symbol stand for, and why a letter?
The input size; a letter lets us describe growth across all sizes at once, not one fixed number.
Difference between input space and auxiliary space?
Input = memory of the data handed to you; auxiliary = the extra scratch you allocate yourself.
Write the total-space formula.
.
When counting space, do we count all cells ever used or the peak at one instant?
The peak — the most cells alive at a single moment.
What does look like as a growth curve?
A flat horizontal line — no growth with .
Why does ?
Big-O keeps only growth shape and drops constants; both are straight lines, so their sum is still a straight line.
What is a stack frame?
A saved block of a paused function call (its locals + return spot) — a sticky note of unfinished business.
Why does recursion of depth cost auxiliary space even if it returns one number?
All frames sit on the call stack simultaneously at peak.
What makes an algorithm "in-place"?
It edits the input directly using only extra cells.
Why do we usually report auxiliary (not total) when comparing algorithms?
The algorithm only controls its scratch; input size is fixed by the caller.