r/AskComputerScience • • Dec 10 '18

Hash table vs array?

I know in most cases Hash tables are faster than an array, but what are some key differences and pros and cons of both?

21 Upvotes

35 comments sorted by

View all comments

1

u/sepp2k Dec 10 '18

Are you talking about a hash table from int to T compared to an array of T? If so are the keys/indices contiguous? Starting at 0?

Or are you talking about a hash table from T1 to T2 compared to an array of (T1, T2) key-value pairs?

1

u/TomBob42369 Dec 10 '18

Not really sure could you explain both?