Hash Tables vs Sorted Arrays

Back to Space-Time Tradeoffs

A classic space-time tradeoff. Hash tables provide O(1) average lookup at the cost of O(n) space and no ordering. Sorted arrays provide O(log n) lookup with O(n) space and ordered iteration. The choice depends on whether fast lookup or ordered access is more important.

computational-complexity space-complexity tradeoff