Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Suppose tasks arrive as A, B, C and D. Which should leave next: A, D, or an item at a specified position? Choose that behaviour before selecting storage.

Reading route

  1. ADTs and contracts: operations, returned results and rejected requests.

  2. Sequences: get, set, insert, append and remove by position.

  3. Stacks: push, peek and pop at the newest end.

  4. Queues: enqueue, front and dequeue in arrival order.

  5. Deques: add, inspect and remove at either end.

  6. Arrays: indexed slots, replacement, shifting and locality.

  7. Dynamic arrays: length/capacity, growth and amortised costs.

  8. Linked structures: traversal, known-node edits and safe reference updates.

  9. Circular-array queues: fixed capacity, wraparound and full-state rejection.

  10. Linked queues: head/tail/size invariants and empty transitions.

  11. Choosing an ADT and representation: compare the same operations under stated assumptions.

Each ADT reading follows purpose → operation contracts → representation and invariant → trace → implementation → implementation choices and correctness → time/space costs → suitability → self-checks. Implementation readings connect those contracts to storage mechanics rather than inventing a new ADT. Every reading starts with goals and prerequisites and ends with two open prediction checks.

Common operation families

FamilyWhat the client must know
Insert/addWhere the record goes; additions here return None
InspectWhich record is returned without changing the collection
Remove/extractWhich record disappears; these removal methods also return it
ReplaceSequence set changes an existing record without changing length
Size/emptysize() and len agree; is_empty() tests whether that count is zero

Empty endpoint access raises IndexError. The sequence page specifies valid indices; the fixed circular queue specifies full-state rejection. Duplicate values and None remain legitimate records. Optional search, iteration and arbitrary-value deletion need separate contracts; we do not add them indiscriminately to endpoint ADTs.

Compare implementations without changing the promise

ContractMain code hereAlternatives explained
SequenceStrict-index Python-list wrapperArray shifts, dynamic growth, linked positional access
StackPython list with top at the backLinked head as top
QueueRestricted library-deque adapter, fixed circular queue, linked head/tail queueList front removal and its shifting cost
DequeLibrary-deque adapter with explicit first/last namesCircular buffers and doubly linked endpoints

The wrappers are complete implementations of their stated interfaces; they delegate underlying library storage management. Linked known-node updates are low-level examples, not a complete positional linked-list class. We do not supply a second full deque allocator. All code uses ordinary Python and the standard library, with no notebook or additional package.

Review Topic 1’s ADT introduction, objects and references, classes and invariants and algorithm analysis. Later topics develop maps, sets and priority queues as separate ADT families.

Start with contracts, or use the concept index for an individual operation.

Code listings offer Python, JavaScript and Julia tabs where a runnable example is present. Python remains the explanation and trace language; see the language guide for native conventions and runnable topic downloads.