Extra memory an algorithm allocates beyond the input (temp vars, helper arrays, recursion stack).
What is total space?
Input space + auxiliary space.
Why do we usually report auxiliary space when comparing algorithms?
Because the algorithm controls only the scratch memory; input size is fixed by the caller.
What hidden cost does recursion add to space?
The call stack — depth × frame size; max simultaneous frames count as auxiliary space.
Auxiliary space of in-place array reversal?
O(1).
Auxiliary space of naive recursive Fibonacci?
O(n) (max stack depth), NOT O(2^n) which is its time.
Merge sort vs quick sort auxiliary space?
Merge O(n) (temp array); Quick O(log n) average (recursion stack).
Total space formula?
Total = S_input + S_aux.
Why is storing all subsets O(2^n · n) space?
There are 2^n subsets, each up to n elements long.
A function with 5 scalar locals and no arrays — auxiliary space?
O(1), constant count independent of n.
Recall Feynman: explain to a 12-year-old
Imagine you're given a big box of LEGO (that's the input). To build something, you sometimes grab an empty tray to sort pieces on the side — that tray is your auxiliary space, the extra stuff you brought out. Total space is the box plus the tray together. A smart builder uses a tiny tray (less auxiliary). And careful! If you keep starting new little side-projects one inside another (recursion), each one needs its own little tray, and they all sit on the table at once — that's a sneaky pile of trays you forgot to count.
Dekho, jab bhi koi algorithm chalta hai, usko memory chahiye hoti hai. Ye memory do parts mein baat lo: ek to input space — jo data tumhe diya gaya hai (jaise ek array of size n), aur dusra auxiliary space — jo extra scratch tum khud banate ho (temp variables, helper arrays, ya recursion ka stack). Total space = input + auxiliary. Bas itni si baat hai, par interview mein log galti yahin karte hain ki kaun sa poocha gaya hai.
Jab hum compare karte hain ki "konsa algorithm zyada smart hai memory bachane mein", tab hum mostly auxiliary dekhte hain — kyunki input ki size to caller ne fix kar di, usme tumhara koi control nahi. Lekin agar real machine pe footprint dekhna ho, tab total chahiye.
Sabse sneaky cheez hai recursion. Log sochte hain "function to bas ek number return karta hai, koi extra memory nahi". Galat! Har pending recursive call apna ek stack frame rakhti hai jo return hone tak zinda rehta hai. Agar depth n hai, to n frames ek saath table pe pade hain — yani O(n) auxiliary space. Isiliye recursive sum O(n) space leta hai, par iterative loop wala sirf O(1).
Yaad rakhne ka shortcut: "AUX = jo main add karta hoon, TOTAL = jo main hold karta hoon." Aur recursion ke liye — "deep stack matlab chhupi hui space." Bas itna samajh lo to space complexity ke questions clear ho jayenge.