With respect to abstract datatypes (ADTs), are the terms "dictionary" and "associative array" perfect synonyms or are there slight differences between them?
2 Answers
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.
- An Introduction to the Analysis of Algorithms by R. Sedgewick and P. Flajolet (2nd ed, 2013)
- Introduction to Algorithms by T. H. Cormen, C. E. Leiserson, R. L. Rivest and C. Stein (3rd ed, 2009)
- Algorithms by R. Sedgewick and K. Wayne (4th ed, 2011)
Depends on the language. On the abstract level of this computer science concept, they are fundamentally synonyms. They are the same thing. One of those concepts where multiple people came up with terms for the same principle concept. If one wants to get too analytical, it might require research to the original coining of the respective terms and the nuances of the implementation of code in relation to the terms used. However, the developers of various programming languages may use a variety of terms and apply the term in different ways. In some cases, some programming languages have multiple implementations of what are basically hash tables and are applied slightly differently. Like Javascript (ES6 and later), Object and Map. Fundamentally, both are associative arrays or hash tables. They differ in specifics and more to do with syntax and specific application of use. There is technical difference between using Objects and Maps. Underlying its core is hash tables (or also known as associative arrays and other terms).
So if you apply the terms in the context of specific programming languages, the answer differs and sometimes they mean precisely the same thing or sometimes they don't and matters you know the language context you are speaking to.
On the general computer science level, they are interchangeable terms but it can also be a bit convoluted and involved to delve into difference in academic nuances as it relates to original use and coinage of terms. In practice, in the real world, we need not be so anal and nitpicky.
Trying to be specifically to an exact answer to the question isn't going to come to a conclusion of a single right answer. The history of the wild west age of computing in the pioneering days have made things complicated especially during the 1970s through 1990s and even since then when the computer field exploded from big machines in corporate facilities and academic campus facilities (universities namely), and some research labs to literally the masses. With that, the computer science terms were in no way set in stone. So you could have dozens of terms that essentially means the same thing.
Unfortunately, that's the inconvenient truth of our beloved field.
- 11
- 2