Data Structures & Algorithms · Interview question

What is a lookup table and what tradeoff does it make?

A strong answer

A lookup table precomputes the results of an expensive function over a bounded input domain and stores them, so at runtime you replace the computation with a direct indexed array read, O(1) instead of O(k). It's the concrete form of the space-time tradeoff: you spend memory (the table) to save time (the computation), paying the computation cost once at build or init time rather than on every call. The classic embedded examples are a sine table replacing trig math in an audio or motor-control ISR, and a 256-entry CRC table replacing a bit-by-bit checksum loop so you can checksum at line rate. It's worth it precisely when the computation is expensive relative to a memory read and the input domain is small enough to tabulate (or to tabulate coarsely and interpolate).

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Lookup Tables & Precomputation

Trade memory for time: precompute expensive results into a table and replace an O(k) runtime computation with an O(1) array read, the space-time tradeoff that powers DSP, trig, and CRC.

More Lookup Tables & Precomputation questions

Browse all 472 interview questions