--

Average time compexity of O(1) and O(n) can start looking really similar when n=5. The thing about theoretical time complexity is that in many cases this leads to outperformance of theoretical "best solutions" in practical environments - if hashmaps always take a permanent, say, 20 ns, but arrays take 2*n ns, they'll outperform the hashmaps until 10 members. That's what I was checking here.

The 'saving hashes' is really interesting, makes sense in retrospect but I didn't know that! So in fact, the REAL time guzzler would be in building the hashmaps in the first place, when you calculate the has, and not in the retrieval.

--

--

Yair Morgenstern
Yair Morgenstern

Written by Yair Morgenstern

Creator of Unciv, an open-source multiplatform reimplementation of Civ V https://github.com/yairm210/Unciv

No responses yet