Data structures and cost conventions
First identify the required operation and the information already supplied. Access by index, search by key and access through a node pointer are different tasks. Storage layout determines which steps are constant time.
1.1 Abstract operations and representation
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks · DA 2024–2026 (3 papers): 1 question, 1 mark
An abstract data type specifies operations and their behaviour. A representation supplies memory layout and algorithms: a stack can use an array or a linked list, for example. A sequence has an order; a set has distinct members; a dictionary associates keys with values. A priority queue removes an extreme key, whereas an ordinary queue removes the earliest outstanding arrival.
| Representation | Access item at index | Find a specified key | Change local links or a known cell |
|---|---|---|---|
| Contiguous array, items | worst case without order/index | overwrite; insertion may shift items | |
| Singly linked list, head only | worst case | worst case | if all required adjacent nodes are known |
| Doubly linked list | worst case | worst case | unlink given a node, with head/tail updates |
Here is the number of stored items. A bound assumes fixed-size keys, values and machine-word pointer operations. Comparing long strings or copying large records has an additional cost. Auxiliary space excludes the input and required output unless the question says otherwise.
1.2 Operation sequences and amortised costs
Worst case is the largest cost of one operation or one entire specified sequence. Expected cost uses a stated probability model. Amortised cost bounds an entire sequence without assuming random inputs. is an upper bound, a lower bound and a tight bound; constants and sufficiently small inputs do not determine asymptotic growth.
For an array that doubles capacity when full, copied item counts form . Over appends, fewer than old items are copied and new items written: total less than item writes. Each append is therefore amortised although a resizing append costs . This assumes unit-cost item copies and geometric capacity growth; fixed-increment growth does not give the same bound.
Last-minute recall
- State what one primitive step means.
- A pointer to a node is not a pointer to its predecessor.
- Separate a key search from a known-location update.
- Multiply costs by operation counts; use changing sizes when necessary.
- Amortised constant time allows occasional linear-time operations.
- Arrays support indexing; linked lists follow links.