📄 Paper 1 · 4.2 Data Structures
⭐ Pro
4.2.7 Dictionaries
AQA 7517 · A-Level Computer Science · ~14 min read

What is a Dictionary (Abstract Data Type)?

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.

Dictionary Operations

OperationDescription
Add / SetInsert a new key-value pair (or update value if key exists)
Delete / RemoveRemove the key-value pair for a given key
Lookup / GetReturn the value associated with a given key
Keys()Return a list of all keys
Values()Return a list of all values
Contains / HasKeyReturn TRUE if a key exists in the dictionary

Dictionary as ADT vs Implementation

As an abstract data type, a dictionary defines the interface (what operations are supported) without specifying the underlying data structure. Common implementations:

  • Hash table — O(1) average for lookup/insert/delete
  • Balanced BST — O(log n) for all operations, but keeps keys sorted

Dictionaries in AQA Pseudocode

// 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"]

Key Properties of Dictionaries

  • Keys are unique — each key appears at most once
  • Unordered — no guaranteed order of key-value pairs (unlike arrays)
  • Mutable — key-value pairs can be added, removed, or updated
  • Keys can be any hashable type — strings, integers, etc.
  • Values can be any type — including lists, nested dictionaries

Applications

  • Storing student records (student ID → name/grade)
  • Configuration settings (setting name → value)
  • Counting word frequencies (word → count)
  • Implementing caches and lookup tables
  • JSON data representation
Exam tip: Know that a dictionary is an ADT defined by key-value pair operations, not a specific implementation. Keys must be unique; values need not be. The underlying implementation is typically a hash table (O(1) average) or BST (O(log n)). Be able to write pseudocode using dictionary operations.
Click through the slides at your own pace. Use arrow keys or click to advance.
Click slide or press arrow keys to navigate

Worksheet — 4.2.7 Dictionaries

8 questions · instantly marked · AQA 7517 standard

Q1Define a dictionary as an abstract data type. What does it store?[2]
✅ Mark scheme
Mark scheme
A dictionary is an ADT (abstract data type) [1]; that stores an unordered collection of key-value pairs where each key is unique [1].
Q2State four operations that can be performed on a dictionary.[4]
✅ Mark scheme
Mark scheme
Any four: Add/Set — insert key-value pair [1]; Delete/Remove — remove by key [1]; Lookup/Get — retrieve value by key [1]; Keys() — return all keys [1]; Values() — return all values [1]; Contains/HasKey — check if key exists [1].
Q3What is the difference between a dictionary as an ADT and its implementation?[2]
✅ Mark scheme
Mark scheme
The ADT defines the interface — what operations are supported — without specifying how it is stored [1]; the implementation defines how it is actually stored (e.g. using a hash table or balanced BST) [1].
Q4Write AQA pseudocode to create a dictionary 'scores', add keys "Alice"=90 and "Bob"=75, then output Alice's score.[3]
✅ Mark scheme
Mark scheme
scores ← {} [1]; scores["Alice"] ← 90, scores["Bob"] ← 75 [1]; OUTPUT scores["Alice"] [1].
Q5Why must keys in a dictionary be unique?[2]
✅ Mark scheme
Mark scheme
If duplicate keys were allowed, a lookup by key would be ambiguous — the system would not know which value to return [1]; the key is the identifier/index for the associated value, so it must be unique within the dictionary [1].
Q6State two common implementations of a dictionary ADT and give the time complexity of lookup for each.[4]
✅ Mark scheme
Mark scheme
Hash table — O(1) average lookup [2]; Balanced BST — O(log n) lookup [2].
Q7A dictionary stores {"red":1, "blue":2, "green":3}. Describe what happens when we add key "red" with value 5.[2]
✅ Mark scheme
Mark scheme
Since "red" already exists as a key, the existing value (1) is overwritten/updated with the new value (5) [1]; the dictionary becomes {"red":5, "blue":2, "green":3} [1].
Q8Give two real-world applications where a dictionary ADT would be appropriate.[2]
✅ Mark scheme
Mark scheme
Any two: student ID → record lookup system [1]; counting word frequencies in text [1]; configuration file storage [1]; caching (URL → cached response) [1]; phone book (name → number) [1].
Topic Quiz
Question 1 of 15
You scored
out of 15
Card 1 of 8
Click to reveal definition
🎉
All cards reviewed!
TermDefinition
🎯

Mini Test — Dictionaries

10 questions · 10 minutes

← 4.2.6 Hash Tables
17 of 70 · AQA 7517
4.2.8 Vectors →