can some one tell me the difference between hash tables and linked list please. I am very confused

February 10th, 2014, 08:17 AM

GregBrannon

Re: Need help with hash tables in my code

Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

And please don't post topics requesting help in the Member Introductions area. I moved the thread to a more appropriate sub-forum.

February 11th, 2014, 05:50 AM

andbin

Re: Need help with hash tables in my code

Quote:

Originally Posted by sarbu_192

can some one tell me the difference between hash tables and linked list please. I am very confused

At conceptual level (not strictly related to Java):

A linked list is a data structure composed by N nodes where each node has a "pointer" to the next node (the last node has a "null" next). So there is a chain of nodes and you need to keep a pointer to the "head" of the list. If you want to find the n-th node, you have to scan the list node by node. Note that there is also the concept of "double" linked list. Here a node has 2 pointers: to the previous and to the next node.

An hash table has a more complex structure. Firstly it has a list (generally an indexable list or array, never a "linked" list) that is known as the "buckets" list. Each bucket is a sort of container for more elements that share the same feature (in Java this "feature" is based on the hashCode() ). The main goal is to distribute elements among the buckets in an quite even way. Think to a big encyclopedia you can have at home, where each volume groups all words with the same initial. All words are distributed quite evenly. And you are very close to this.
Under a "bucket" there is generally a linked list where each item has a key and a value. Once you find the right bucket, you need to scan this linked list to find the value by the key.