Why might you choose an algorithm with higher time complexity if it has lower space complexity?
Think about your answer, then reveal below.
Model answer: When memory is the bottleneck — such as on embedded systems, when working with data too large to fit in RAM, or when cache efficiency matters more than raw operation count — a more memory-frugal algorithm can outperform a theoretically faster one in practice.
Complexity analysis measures growth rate in an idealized model, but real hardware has memory hierarchies (L1/L2/L3 cache, RAM, disk). An algorithm that needs O(n) auxiliary space may thrash the cache or require paging to disk for large inputs, making its actual runtime worse than an in-place O(n²) algorithm. This time-space trade-off is fundamental to practical algorithm selection.