Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the true difference between a dictionary and a hash table?

I've always used dictionaries. I write in Python.

like image 293
TIMEX Avatar asked Jan 13 '10 23:01

TIMEX


People also ask

What is the difference between hash table and dictionary?

In Hashtable, you can store key/value pairs of the same type or of the different type. In Dictionary, you can store key/value pairs of same type. In Hashtable, there is no need to specify the type of the key and value. In Dictionary, you must specify the type of key and value.

What is the difference between dictionaries and hashes?

A dictionary is a general concept that maps unique keys to non-unique values. But the Hash is a data structure that maps unique keys to values by taking the hash value of the key and mapping it to a bucket where one or more values are stored.

What is difference between dictionary and Hashtable in Python?

Hashtable is a loosely typed (non-generic) collection, this means it stores key-value pairs of any data types. Dictionary is a generic collection. So it can store key-value pairs of specific data types.

What's the difference between HashMap and dictionary?

In Java the HashMap implements the Map interface while the Dictionary does not. That makes the Dictionary obsolete (according to the API docs). That is, they both do a similar function so you are right that they seem very similar...a HashMap is a type of dictionary. You are advised to use the HashMap though.


1 Answers

A dictionary is a general concept that maps keys to values. There are many ways to implement such a mapping.

A hashtable is a specific way to implement a dictionary.

Besides hashtables, another common way to implement dictionaries is red-black trees.

Each method has it's own pros and cons. A red-black tree can always perform a lookup in O(log N). A hashtable can perform a lookup in O(1) time although that can degrade to O(N) depending on the input.

like image 195
R Samuel Klatchko Avatar answered Oct 03 '22 23:10

R Samuel Klatchko