Abstract data type
A collection of operations and their behavior, independent of implementation: a stack is last-in-first-out, a queue first-in-first-out, and a dictionary associates keys with values.
REFERENCE SHEET
Choose a representation by the operations and guarantees the application needs.
Before this Proof techniques
A collection of operations and their behavior, independent of implementation: a stack is last-in-first-out, a queue first-in-first-out, and a dictionary associates keys with values.
Arrays offer constant-time indexed access in a word-RAM model. Linked lists offer constant-time insertion after a known node, but finding that node may take linear time.
A bound on the total cost of every allowed operation sequence, spread over its operations. It does not assume a random input distribution.
Starting with fixed positive capacity, appending n items while doubling capacity when full takes O(n) total element writes and copies. Each append is O(1) amortized, although a resize takes Θ(n) at that moment.
An array-based binary heap supports finding its extremum in O(1) and insertion or extraction in O(log n) worst-case time. Bottom-up construction takes O(n).
With bounded load factor and suitable uniform hashing assumptions, chaining gives expected O(1) lookup. Worst-case lookup can still take Θ(n).
A heap is a natural priority queue when repeatedly processing the next event.
A queue supports BFS layers; a stack supports DFS exploration.
01 / Analyze
List the capacities that become full before the last append.
Copies occur at capacities 1, 2, 4, and 8, totaling 15. There are also 9 writes of new items. An expensive final operation is compatible with a linear total.
02 / Choose
Distinguish minimum access from arbitrary key lookup.
A min-heap: read the minimum in O(1), insert in O(log n), and extract the minimum in O(log n). A sorted array has fast access but generally linear-time insertion.
These sheets use this topic as a prerequisite.
Further reading and full-length treatments: