Are hash tables essentially multidimensional arrays?
2008-01-15 11:04:43 UTC
Hash tables allow you to make lookup tables right? Well you can do that with 2 dimensional arrays, right?
Eight answers:
lansingstudent09101
2008-01-15 15:10:35 UTC
A multi-diminsional array is one implementation of a hash table (a bad one in most circumstances).
It is more likely an array of some other "linked" datastructure using pointers. This way any "bucket" can be filled with an infinite number of items if the data requires it (though this may mean you want to use a better hashing function or have each hash table contain a hash table, that is full of linked lists).
Daniene
2016-04-05 09:58:37 UTC
A few thing to clarify. The difference between these techniques is mor than just speed. The is a convenience and capability difference between them as well. Arrays will be fastest in general because they are direct accesses. Give an index get a value. You loss scalablity. Link list would be next fastest but you have control of the implementation sometimes and you could mess it up. Also to get a value is more memory accesses have to be done. So technically slower but the data size is not predetermined. Last is a hash because it gives you content addressable access to the data. If you don't need that feature and the over head it adds then you would not use it. But if you need the feature and the implementation is a good one this data structure could be faster than anything the average programmer could write on there own. Since these 3 techniques are not really the same saying which is the fastest depends. On the problem being solved. If the problem optimally needs the features provided by the technique then it will be the fastest. Your secondary question about creating a hash out of a array or a linked list shows this difference. Some problems the array approach will be faster ands others the linked list approach will be faster. It will depend on how often and in what manner the problem needs to,probe back into the structure after creation.
No. They are a method to solve key-value mappings. They *can* be implemented using multidimensional arrays.
"Hash tables allow you to make lookup tables right?"
You have it backwards. Hash tables can be used for implementing lookup tables. It may be semantics, but that *is* what programming is all about.
"Well you can do that with 2 dimensional arrays, right?"
If you mean a linear search, then the two are nothing alike. A hash table implements a hash function which is designed to produce an index based on manipulation of the provided key. How this has function works is based on the type and range of data.
The purpose of a has function is to determine a table index with minimal calculations in comparrison to a linear search, or other form of search process.
lordpil
2008-01-15 11:17:28 UTC
A hash table is simply a type of data structure, as is a two-dimensional array. There is really no such thing as a two-dimensional array on a classical computer. The bytes are still lined up sequentially in the address space, it's just convenient to think of it as a two dimensional array.
The particular usefulness of a hash table is lookup by a key value. This required a tailored hash function to associate the vales. In a typical 2d array, you may have values indexed by a number parameter, so in order to look up by a key, you'd need to search the entire list, rather than simply apply a hash function to determine the index.
davidvanpaten
2008-01-15 11:42:49 UTC
A hashtable is not a multidimensional array unless you are using chaining for multiple hits. If you were to use another method of collision resolution like linear probing you don't need another dimension to your array. Correct me if I'm wrong but I think these are the only two ways to handle collision resolution.
Kamran
2008-01-15 11:12:36 UTC
Hashtables are good for Key/Value pairs. But it really is just a fancy array. I think with HT you can do a few more things with it. You also dont have to worry about defining the arrays and such.
2014-12-11 00:16:32 UTC
difficult thing. lookup onto a search engine. that will can help!
CatNip
2008-01-15 11:12:41 UTC
You could do that, but it wouldn't be very efficient, nor would it be scalable.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.