Day 318 — Containers, their complexity, and their constant factors

Sunday, 20 June 2027 · Week 46 of 52 · Production · Study day · 60 min

Choosing a container by its complexity class alone is how you end up with an asymptotically optimal book that is slower than an array, and knowing why is a standard interview subject.

What you should be able to do tonight

  • Choose the right container for an order book’s two access patterns and defend each choice.
  • Say when a vector beats a hash map despite worse complexity, and demonstrate it.

Tasks 60 min

35 min Measure the constant factors: time lookups in a vector, a sorted vector with binary search, an unordered map and an ordered map, across sizes from 8 to 100,000 elements. Plot time against size for all four. Below a few hundred elements the linear scan over a contiguous vector usually wins, and that crossover point is the thing to know.

25 min Apply it to the design: an order book has few price levels near the touch and many orders, so the price levels want a sorted contiguous structure and the order lookup wants a hash map. Write the design down with the reasoning attached, since it is exactly the question that gets asked.

Resources

Deliverable

Lookup timings for four containers across six sizes with the crossover identified, plus a written order book data structure design.

Checkpoint

Why might a linear scan over a vector beat a hash map lookup, and at roughly what size does that stop being true?

Prepare for tomorrow

Ten minutes tonight so Day 319, Monday, 21 June 2027 starts clean. This is what the evening email sends you.

Find the matching engine or order book component in the LEAN repository or any open source exchange simulator.

Read the main data structures without trying to follow the whole flow.

Note the two decisions they made that differ from your design.