LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

How does a map built on an unsorted list work, and why does even put cost $O(n)$?

Entries sit in a list in any order; every operation scans the list for the key. put must scan too, because it has to check whether the key already exists before it may append.

A doubly linked list between header and trailer sentinels holding entries 9, 6, 5 and 8 in no particular order

* The entries are in arrival order, not key order, so finding a key means walking the list. *

The entries are stored in a doubly linked list S, in whatever order they arrived. All three operations walk S with an iterator:

  • get(k): return the value of the first entry whose key equals k; at the end of the list return null.
  • put(k, v): if an entry with key k turns up, replace its value and return the old one. Only if the scan reaches the end without a match, append (k, v) with addLast and return null.
  • remove(k): if found, unlink the entry and return its value; otherwise null.

Appending to a linked list is $O(1)$, but put cannot append blindly: the one-entry-per-key rule forces it to search first. In the worst case (key absent, or at the end) every operation touches all n entries, so all three are $O(n)$.

Whether S is a doubly linked list, a singly linked list or an ArrayList, and whether new entries go to the front or the back, does not matter. Nor does the implementation change what the operations return: every map implementation must behave identically through its interface, and only the speed differs.

That is fine for a handful of entries and useless for a large map. The rest of this topic is about the hash table, which brings the expected cost down to $O(1)$.

From Quiz: ADS / Sets, Maps and Hash Tables | Updated: Nov 26, 2026