A set is an unordered collection of unique elements — no duplicates allowed.
| Operator | Description |
|---|---|
empty → Set |
Create empty set |
insert(Set, Element) → Set |
Add element (ignored if already present) |
remove(Set, Element) → Set |
Remove element |
member(Set, Element) → Boolean |
Test membership |
union(Set, Set) → Set |
All elements in either set |
intersection(Set, Set) → Set |
Elements in both sets |
difference(Set, Set) → Set |
Elements in first but not second |
Tracking visited nodes in a graph traversal. Storing unique usernames.
KEY TAKEAWAY: Use a set when uniqueness matters and order does not.
A list is an ordered sequence of elements that allows duplicates.
| Operator | Description |
|---|---|
empty → List |
Create empty list |
prepend(List, Element) → List |
Add to front |
append(List, Element) → List |
Add to back |
head(List) → Element |
Return first element |
tail(List) → List |
Return all except first |
isEmpty(List) → Boolean |
Test if empty |
length(List) → Integer |
Number of elements |
Maintaining an ordered sequence of steps, storing a history of actions.
An array is an ordered, indexed collection of fixed size.
| Operator | Description |
|---|---|
create(n) → Array |
Create array of size n |
get(Array, index) → Element |
Access element at index |
set(Array, index, Element) → Array |
Update element at index |
length(Array) → Integer |
Fixed size |
Storing tabular data, dynamic programming tables, adjacency matrices for graphs.
EXAM TIP: Arrays differ from lists in that they allow direct indexed access in $O(1)$. Lists may require traversal to find an element.
A dictionary stores key–value pairs, allowing efficient lookup by key.
| Operator | Description |
|---|---|
empty → Dictionary |
Create empty dictionary |
insert(Dict, Key, Value) → Dict |
Add or update key-value pair |
lookup(Dict, Key) → Value |
Retrieve value for key |
delete(Dict, Key) → Dict |
Remove key-value pair |
hasKey(Dict, Key) → Boolean |
Check if key exists |
keys(Dict) → Set |
Return all keys |
Mapping city names to populations, storing adjacency lists for graphs, implementing caches.
# Python dict — the built-in Dictionary ADT
city_pop = {"Melbourne": 5000000, "Sydney": 5300000}
city_pop["Brisbane"] = 2600000
print(city_pop["Melbourne"]) # 5000000
COMMON MISTAKE: Confusing a dictionary with a list. Dictionaries use keys (not integer indices) for lookup, and insertion order is not guaranteed in all implementations.
| Property | Set | List | Array | Dictionary |
|---|---|---|---|---|
| Ordered | No | Yes | Yes | No |
| Indexed | No | No (typically) | Yes | By key |
| Duplicates | No | Yes | Yes | No (keys unique) |
| Key-value | No | No | No | Yes |
| Dynamic size | Yes | Yes | No | Yes |