A dictionary (also called a map or associative array) is an ADT that stores an unordered collection of key-value pairs. Each key is unique and is used to look up its associated value.
Dictionaries are typically implemented using hash tables, giving O(1) average-case operations.
| Operation | Description |
|---|---|
| Add / Set | Insert a new key-value pair (or update value if key exists) |
| Delete / Remove | Remove the key-value pair for a given key |
| Lookup / Get | Return the value associated with a given key |
| Keys() | Return a list of all keys |
| Values() | Return a list of all values |
| Contains / HasKey | Return TRUE if a key exists in the dictionary |
As an abstract data type, a dictionary defines the interface (what operations are supported) without specifying the underlying data structure. Common implementations:
// AQA 7517 pseudocode — dictionary creation and access
student_grades ← {} // empty dictionary
// Add key-value pairs
student_grades["Alice"] ← 85
student_grades["Bob"] ← 72
student_grades["Charlie"] ← 91
// Lookup
OUTPUT student_grades["Alice"] // outputs 85
// Delete
REMOVE student_grades["Bob"]
8 questions · instantly marked · AQA 7517 standard
| Term | Definition |
|---|
10 questions · 10 minutes