Comment

Comment by deaddabe

> Data structures and algorithms: We used a dictionary instead of a list to go from O(S) to O(1) operations.

The list in TFA is so small that I wonder at what point creating a hashtable is more economical than going through a 9 items arrays. In C, accounting for allocations, etc. I would not be surprised that strcmp on an static array would be faster.

As always, measure with benchmarks (which does the article, but not on array vs. hashtable). In theory, O(1) is better than O(N). In pratice, with memory allocations and all, the order of magnitude of N plays a role.

Anyways, I would have used a hashtable also to convey the idea that I only want to check if the item is in the list. Python makes this easy. In C, I would have used an array unless N is "large enough".

parent deaddabe 4 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton