1
$\begingroup$

With respect to abstract datatypes (ADTs), are the terms "dictionary" and "associative array" perfect synonyms or are there slight differences between them?

$\endgroup$
  • $\begingroup$ What research have you done? Can you express either in ADT form? What kind of "associative array" are you talking about? (In some dynamic languages, ass. arrays can store key-value pairs of arbitrary type, which is not usually how dictionaries are viewed.) $\endgroup$ – Raphael Sep 15 '14 at 10:25
  • $\begingroup$ @Raphael So you're saying they're not two words for the same thing then? I've always used the words interchangeably; apparently, so has the Internet. $\endgroup$ – sgarza62 Sep 15 '14 at 12:55
  • 1
    $\begingroup$ I'd be very hesitant to try to draw any meaningful distinction between these terms if you expect anybody else to have the same distinction(s) in mind. When in doubt, if it matters and in a way that's appropriate for your intended audience, explain briefly what properties the thing you're talking about has. When consuming communications, listen for the author's clarification; if not present, assume whatever comes to mind and is consistent with the presentation. $\endgroup$ – Patrick87 Sep 16 '14 at 6:52
  • 1
    $\begingroup$ Such clarification questions are useful. But people expect the asker to show some investigation of his own. Hence the variations of the question grading between positive and negative, i.e. around 0. But, maybe, the importance of this should be stressed more explicitly in the introductory tour. CC@Patrick87 $\endgroup$ – babou Sep 16 '14 at 8:14
5
$\begingroup$

As far as I can tell, associative array is a newer term, maybe emerging from popular use in dynamic programming languages. In algorithms as an academic field, it seems to denote a generalisation of the dictionary but one usually works with dictionaries (probably because most resource characteristics carry over so one does not need to complicate notation).

Citing from theory-leaning [1, p281] (bold emphasis mine):

The dictionary, symbol table, or simply search problem is a fundamental one in computer science: a set of distinct keys is to be organized so that client queries whether or not a given key is in the set can be efficiently answered. More generally, with distinct keys, we can use binary search trees to implement an associative array, where we associate information with each key and can use the kry to store or retrieve such information.

CLRS [2, p229] make no mention of associative arrays but define dictionaries:

We call a dynamic set that supports [insertion, deletion and membership test] a dictionary.

In the more practically inclined [3, p361 ff], the term symbol table is used as a synonym for dictionary but defined in a slightly different way:

A symbol table is a data structure for key-value pairs that supports two operations: insert (put) a new pair into the table and search for (get) the value associated with a given key.

Later, they write:

[The conventions "no duplicate keys" and "put on an existing key replaces the old value"] define the associative array abstraction, where you can think of a symbol table as being just like an array, where keys are indices and values are array entries.

Summarising this small literature research (which is not without contradictions) and from a theoretical viewpoint, I'd state the following:

  • A dictionary is a data structure that implements a (dynamic) set with insertion, deletion and membership test.

    Mathematically speaking, a dictionary over universe $X$ represents an element of the power set $2^X$ of $X$.

  • An associative array is a data structure that implements a (dynamic) mapping with insertion/update, deletion and retrieval.

    Mathematically speaking, an associative array over key universe $X$ and value universe $Y$ represents an element of the set of functions $X \to Y$.

One can thus view a dictionary over universe $X$ as associative array over $(X,\{0,1\})$; this closely resembles the indicator function of sets.

I think this fits programmers' reality quite well, but terms may be used differently over there.

Important: The usage of the term "array" may suggest $O(1)$ accesses. This can, in general, not be expected to be true; at least not in the worst-case and without amortisation arguments. Implementations using hash tables come closest; see here for a discussion about what to expect w.r.t. performance.


  1. An Introduction to the Analysis of Algorithms by R. Sedgewick and P. Flajolet (2nd ed, 2013)
  2. Introduction to Algorithms by T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein (3rd ed, 2009)
  3. Algorithms by R. Sedgewick and K. Wayne (4th ed, 2011)
$\endgroup$
  • $\begingroup$ I hope those who downvote will explain their views in an answer and substantiate it with credible sources. $\endgroup$ – Raphael Sep 15 '14 at 20:28
  • 1
    $\begingroup$ I think you're overgeneralizing by stating that “dictionary” and “associative array” as having different meanings out of context. You even cite S&R which doesn't distinguish between the two. A (finite) map, a dictionary, a hash (that hash, not that other hash), an associative array are all the same concept of a data structure with an index (usually, but not systematically, with associated data) unless explicitly defined otherwise. $\endgroup$ – Gilles Sep 15 '14 at 20:57
  • $\begingroup$ @Gilles While it is true that the books by Sedgewick contradict each other to some extent, I think my "conclusion" from the perspective of theory is valid. In particular, the OP asks wrt ADTs -- find/contains? is clearly a different operation from get (even though the latter can be used to model the former; pick boolean as value type). What's more, "both are the same" is not a statement that can explain the rich literature that talks about "dictionaries" without ever bothering with stored values (besides the keys themselves). $\endgroup$ – Raphael Sep 15 '14 at 21:30
  • $\begingroup$ Note that my "definition" still admits the point of view "a dictionary is a special kind of associative array"; understanding a set as mapping from the universe to booleans is not uncommon. $\endgroup$ – Raphael Sep 15 '14 at 21:32
  • 1
    $\begingroup$ I mean map as in a data structure, i.e. a finite map = dictionary = associative array = … It's common terminology among both programmers and computer scientists. $\endgroup$ – Gilles Sep 15 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.