views:

108

answers:

6

What is the difference between a Map and a Dictionary? I am not asking for how they are defined in language X or Y(which seems to be what generally people are asking here on SO), I want to know what is their difference in theory.

I know a Map is an object that maps keys to values. Isn't a Dictionary the same? Thanks

+1  A: 

These are two different terms for the same concept.
Hashtable and HashMap also refer to the same concept.

SLaks
Actually, Hashtable/Hashmap imply a specific implementation in their name (vs. say a balanced tree, which is used in the C++ std::map, for example).
Joe
In general, you shouldn't care about the implementation. (Except for performance reasons) Also, that's not always true; look at .Net, for example.
SLaks
+4  A: 

One is an older term for the other. Typically the term Dictionary was used before the mathematical term Map took hold. Also, Dictionaries tend to have a key type of String, but that's not 100% true everywhere.

Edwin Buck
A: 

Other terms for this concept that are fairly common: associative array and hash.

Hank Gay
A: 

Typically I assume that a map is backed by a hash table; it connotes an unordered store. Dictionaries connote an ordered store.

There is a tree-based dictionary called a Trie.

In Lisp, it might look like this:

(a (n (d t)) n d )

Which encapsulates the words:

  • a
  • and
  • ant
  • an
  • ad

The traversal from the top to the leaf yields a word.

Paul Nathan
`Dictionary` in .Net is unordered.
BlueRaja - Danny Pflughoeft
Huh............
Paul Nathan
Cocoa dictionaries are also unordered.
Ken
+4  A: 

Two terms for the same thing

"Map" is used by Java, C++
"Dictionary" is used by .Net, Python
"Associative array" is used by Javascript, PHP

"Map" is the correct mathematical term, but it is avoided because it has separate meaning in functional programming.

See here.

BlueRaja - Danny Pflughoeft
A: 

Yes, they are the same, you may add "Associative Array" to the mix.

using Hashtable or a Hash ofter refers to the implementation.

OscarRyz