Repaso
Español
Algorithms & DSFoundationsALG-52

What is a dictionary (also called map or hash map)?

Options

  1. A set of key-value pairs, looked up by key (Correct option)
  2. An ordered list of numbers, accessed by position
  3. A text file that contains a list of words
  4. A sorting algorithm that is used for text

Answer

A collection of key-value pairs where you look up a value by its key, like a phone book

Why

In a phone book you look up a name (key) and find a number (value). A dictionary works the same way.

Python: ages = {"Ana": 30, "Luis": 25} and ages["Ana"] returns 30. Java: Map<String, Integer> (HashMap).

Looking up a key takes about the same time no matter how big the dictionary is (O(1) on average).

Remember

Dictionary = key → value, fast lookup.

Key terms

Practice this question in Repaso