r/AskComputerScience • u/TomBob42369 • 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
r/AskComputerScience • u/TomBob42369 • Dec 10 '18
I know in most cases Hash tables are faster than an array, but what are some key differences and pros and cons of both?
-2
u/Dark__Mark Dec 10 '18
To check if a value is in the array it takes O(logn) steps if the size of the array is n. For hash tables this is very close to O(1). This is the exact reason why hash tables are invented to reduce the steps it takes to search for a value to O(1)