Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between a HashMap and a dictionary ADT

What is the difference between a Hash Map and dictionary ADT. And when to prefer one over another. For my programming assignment my instructor has asked to use one of them but I don't see any difference in between both. The program is supposed to work with a huge no. of strings. Any suggestions?

like image 684
ashokgelal Avatar asked Nov 06 '08 00:11

ashokgelal


People also ask

What is the difference between HashMap and dictionary in Python?

Hash tables or has maps in Python are implemented through the built-in dictionary data type. The keys of a dictionary in Python are generated by a hashing function. The elements of a dictionary are not ordered and they can be changed.

What is dictionary ADT?

The dictionary ADT provides operations for storing records, finding records, and removing records from the collection. This ADT gives us a standard basis for comparing various data structures. Loosly speaking, we can say that any data structure that supports insert, search, and deletion is a “dictionary”.

Whats the difference between a Map and a dictionary?

The Dictionary is a generic collection that holds data in key-value pairs. On the other hand, the map takes a sequence of objects, applies some change to each of them, and produces a new sequence containing the transformed items.

Is a HashMap a dictionary?

Dictionaries, HashMaps and Associative ArraysA dictionary (also known as a map, hashmap or associative array) is a set of key/value pairs. OpenAPI lets you define dictionaries where the keys are strings.


2 Answers

In terms of Java, both the class HashMap and the class Dictionary are implementations of the "Map" abstract data type. Abstract data types are not specific to any one programming language, and the Map ADT can also be known as a Hash, or a Dictionary, or an Associative Array (others at http://en.wikipedia.org/wiki/Associative_array). (Notice we're making a distinction between the Dictionary class and the Dictionary ADT.)

The Dictionary class has been marked as obsolete, so it's best not to use it.

like image 152
Phil Avatar answered Oct 18 '22 14:10

Phil


This Stack Overflow post does a good job explaining the key differences:

Java hashmap vs hashtable

Note that Hashtable is simply an implementation of the Dictionary ADT. Also note that Java considers Dictionary "obsolete".

The fact that Hashtable is synchronized doesn't buy you much for most uses. Use HashMap.

like image 24
Jim Nelson Avatar answered Oct 18 '22 13:10

Jim Nelson