Show understanding that a stack, queue and linked list are examples of ADTs

10.4 Introduction to Abstract Data Types (ADT)

An Abstract Data Type (ADT) defines what a data structure does – the collection of values it holds and the operations that can be performed on those values – without prescribing how those operations are implemented. In Cambridge International AS & A‑Level Computer Science (9618) the ADT is the contract that client code relies on; the concrete data structure (array, linked list, circular buffer, …) is the implementation that fulfils that contract.


Key Characteristics of an ADT

  • Encapsulation: data and the operations that manipulate it are bundled together.
  • Well‑defined interface: a fixed set of operations (the contract) that the ADT guarantees.
  • Implementation independence: the same ADT can be realised with arrays, linked structures, buffers, etc.
  • Behaviour described by axioms or contracts: e.g. LIFO for a stack, FIFO for a queue, sequential access for a linked list.

Why ADTs Matter in the Cambridge Syllabus

  • Provide a language for reasoning about correctness (AO2).
  • Allow you to swap implementations without changing client code (AO3).
  • Many exam questions ask you to choose the most suitable ADT for a given problem.
  • Paper 4 tasks require you to implement at least one ADT in a permitted language (Java, Python, Visual Basic).

Canonical ADTs Examined in the Curriculum

The three ADTs that are explicitly examined are Stack, Queue and Linked List. Each is introduced abstractly first, then linked to possible concrete implementations.

1. Stack ADT

Concept: Last‑In‑First‑Out (LIFO). The most recently added element is the first that can be removed.

OperationPurposePseudocode (Python‑style)
push(x) Insert element x on the top of the stack.
def push(S, x):
    S.append(x)          # O(1) for list‑based implementation
pop() Remove and return the top element; error if the stack is empty.
def pop(S):
    if not S:
        raise IndexError('pop from empty stack')
    return S.pop()       # O(1)
top() Return the top element without removing it.
def top(S):
    if not S:
        raise IndexError('top of empty stack')
    return S[-1]         # O(1)
isEmpty() True if the stack contains no elements.
def isEmpty(S):
    return len(S) == 0

Mathematical description (optional):

\[ \text{push}(S,x)=S\cdot x,\qquad \text{pop}(S)=\begin{cases} (S',x) &\text{if }S=S'\cdot x\\[2mm] \text{error} &\text{if }S=\varepsilon \end{cases} \]

Typical concrete implementations – fixed‑size array with a “top” index, or a singly‑linked list where push inserts at the head.


2. Queue ADT

Concept: First‑In‑First‑Out (FIFO). The earliest added element is the first that can be removed.

OperationPurposePseudocode (Python‑style)
enqueue(x) Insert element x at the rear of the queue.
def enqueue(Q, x):
    Q.append(x)          # O(1) for list‑based implementation
dequeue() Remove and return the front element; error if the queue is empty.
def dequeue(Q):
    if not Q:
        raise IndexError('dequeue from empty queue')
    return Q.pop(0)      # O(n) for list; O(1) for circular buffer or linked list
front() Return the front element without removing it.
def front(Q):
    if not Q:
        raise IndexError('front of empty queue')
    return Q[0]          # O(1)
isEmpty() True if the queue contains no elements.
def isEmpty(Q):
    return len(Q) == 0

Mathematical description (optional):

\[ \text{enqueue}(Q,x)=\langle q_1,\dots ,q_n,x\rangle,\qquad \text{dequeue}(Q)=\begin{cases} (\langle q_2,\dots ,q_n\rangle , q_1) &\text{if } n\ge1\\[2mm] \text{error} &\text{if } n=0 \end{cases} \]

Typical concrete implementations – circular array (fixed size) or a singly‑linked list with pointers to both front and rear.


3. Linked‑List ADT

Concept: An ordered collection of nodes, each containing data and a reference to the next node (and optionally the previous node). The ADT does not prescribe whether the list is singly‑, doubly‑ or circularly linked – those are implementation choices.

OperationPurposePseudocode (Python‑style, singly‑linked)
insert(i, x) Insert x at position i (0‑based).
def insert(L, i, x):
    if i < 0 or i > L.size:
        raise IndexError('bad index')
    new = Node(x)
    if i == 0:                 # insert at head
        new.next = L.head
        L.head = new
    else:
        prev = node_at(L, i-1)
        new.next = prev.next
        prev.next = new
    L.size += 1
delete(i) Remove the element at position i.
def delete(L, i):
    if i < 0 or i >= L.size:
        raise IndexError('bad index')
    if i == 0:
        L.head = L.head.next
    else:
        prev = node_at(L, i-1)
        prev.next = prev.next.next
    L.size -= 1
get(i) Return the element at position i without removing it.
def get(L, i):
    if i < 0 or i >= L.size:
        raise IndexError('bad index')
    return node_at(L, i).data
size() Number of elements stored.
def size(L):
    return L.size
isEmpty() True if the list contains no elements.
def isEmpty(L):
    return L.size == 0

Implementation variants:

  • Singly‑linked list – fast insertion/deletion at the head (O(1)).
  • Doubly‑linked list – fast insertion/deletion at both ends (O(1) for tail operations).
  • Circular linked list – useful for round‑robin scheduling.

Comparison of the Three ADTs

Property Stack Queue Linked List
Access order LIFO – last element added is first removed FIFO – first element added is first removed Sequential – any position can be accessed (traversal required)
Typical operations push, pop, top, isEmpty enqueue, dequeue, front, isEmpty insert, delete, get, size, isEmpty
Common concrete implementations Array with a “top” index, or singly‑linked list Circular array (buffer) or linked list with front/rear pointers Singly‑linked, doubly‑linked, circular
Time complexity (average case) push / pop – O(1) enqueue / dequeue – O(1) insert / delete at head – O(1); at arbitrary position – O(n)
Space usage Fixed (array) or dynamic (linked) Fixed (circular buffer) or dynamic (linked) Dynamic; one extra reference per node (two for doubly‑linked)

Link to the Cambridge Syllabus (AO1‑AO3)

  • AO1 – Knowledge: Define each ADT, list its operations, and state its abstract properties (LIFO, FIFO, sequential access).
  • AO2 – Analysis: Given a problem statement, decide which ADT best satisfies the requirements and justify the choice (e.g., “use a stack for expression evaluation”).
  • AO3 – Design & Implementation: Write pseudocode or real code that implements the ADT, develop test cases, and analyse time/space efficiency.

Typical exam tasks:

  1. Write pseudocode for push and pop and explain why each runs in O(1).
  2. Choose an appropriate ADT for a “print queue” and describe how you would implement it with a circular buffer.
  3. Given a sequence of operations on a linked list, draw the list after each step (testing understanding of pointers).
  4. Convert an array‑based stack implementation to a linked‑list version without changing the client code.

Practical Activities (Paper 4 preparation)

  • Lab 1 – Stack: Implement a stack in Java and Python, write JUnit/pytest test cases, and measure runtime for 10⁶ push/pop operations.
  • Lab 2 – Queue: Build a circular‑buffer queue, then replace it with a linked‑list version; compare memory usage.
  • Lab 3 – Linked List: Implement singly‑ and doubly‑linked lists, add insert and delete at arbitrary positions, and demonstrate edge‑case handling (empty list, index out of range).
  • Mini‑project: Design a text‑editor “undo” feature using two stacks (undo/redo) – this integrates multiple ADTs and highlights the importance of abstraction.

Quick Audit Checklist – Have You Covered the Syllabus?

Syllabus SectionKey Sub‑topicsWhat to Verify in Your Notes
1 Information representation Binary, hexadecimal, BCD, ASCII/Unicode, two’s‑complement, floating‑point, rounding errors Conversion tables, example of BCD, floating‑point representation exercise
2 Communication LAN/WAN, client‑server vs P2P, topologies, Ethernet, CSMA/CD, IP addressing (IPv4/IPv6), DNS, URLs, cloud computing, protocol stack (TCP/IP), HTTP/FTP/SMTP OSI/TCP‑IP diagram, short network‑design question, protocol‑layer table
3 Hardware CPU components, RAM/ROM types, embedded systems, buffers, sensors/actuators, parallel processing, RISC vs CISC, Boolean algebra, Karnaugh maps, flip‑flops Annotated CPU block diagram, truth‑table for a half‑adder, Karnaugh‑map example
4 Processor fundamentals Von Neumann model, registers, ALU, CU, bus architecture, fetch‑execute cycle, interrupts, pipelining, multi‑core, virtual memory, paging/segmentation, scheduling algorithms Step‑by‑step fetch‑execute illustration, sample interrupt‑service routine pseudocode
5 System software OS functions, utility software, libraries, assemblers, compilers, interpreters, IDE features, translation phases, BNF, RPN Comparison table (compiler vs interpreter), simple BNF grammar for arithmetic expressions
6 Security & data integrity Threats, firewalls, encryption basics, authentication, data validation/verification, symmetric & asymmetric encryption, SSL/TLS, digital certificates, quantum cryptography Caesar‑cipher vs RSA walkthrough, validation checklist for a data‑entry form
7 Ethics & ownership Professional ethics, copyright, software licences, AI impact, social/economic/environmental implications Case‑study analysis (open‑source vs proprietary)
8 Databases Relational model, ER diagrams, normalisation (1NF‑3NF), SQL basics, primary/foreign keys, integrity constraints Sample ER diagram, normalisation exercise, simple SELECT/INSERT statements
9 Algorithms & problem solving Flowcharts, pseudocode conventions, searching & sorting (linear, binary, bubble, insertion, selection), recursion, Big‑O analysis Annotated flowchart, pseudocode for binary search, O‑notation table
10 Data structures (ADTs) Stack, Queue, Linked List (including singly, doubly, circular), array‑based vs linked implementations, use‑case justification All content from this note – definitions, operations, pseudocode, comparison, exam‑style questions

Actionable Improvement Suggestions (once your full lecture notes are available)

  1. Map every syllabus sub‑topic to a note section using the checklist above. Highlight any gaps in red and add the missing material.
  2. Integrate examples that mirror past paper questions. For each ADT, include a short “exam‑style” scenario (e.g., evaluating a postfix expression with a stack) and a step‑by‑step solution.
  3. Provide side‑by‑side pseudo‑code vs real code (Java and Python) for at least one concrete implementation of each ADT. This satisfies AO3 requirements and aids students who prefer a specific language.
  4. Include a concise “contract” box for each ADT that lists the operations, their pre‑conditions, post‑conditions and expected time complexity. This reinforces the abstract nature of the ADT.
  5. Add quick‑reference tables for:
    • Time/space complexity of each operation (array vs linked implementation).
    • When to prefer a stack, queue or linked list (decision‑making flowchart).
  6. Embed self‑checking questions after each major section (e.g., “What will be the output of the following sequence of stack operations?”) with answer keys.
  7. Link theory to practical tasks by stating the exact AO3 assessment criteria that each lab or mini‑project satisfies.
  8. Ensure consistent terminology with the official syllabus (e.g., use “enqueue”/“dequeue” rather than “add”/“remove” for queues).
  9. Review formatting – headings should follow a logical hierarchy (h2, h3, h4), tables must have clear captions, and code blocks should be uniformly indented.
  10. Proofread for accuracy – verify that all mathematical descriptions, complexity claims and example outputs are correct.

Summary

Stacks, queues and linked lists are the cornerstone ADTs for Cambridge International Computer Science. Mastering them at the abstract level enables you to:

  • Reason about algorithmic correctness (AO2).
  • Design flexible programs that can change implementation without affecting client code (AO3).
  • Answer a wide range of knowledge, analysis and programming questions in the examinations.

Use the tables, pseudocode, and checklist in this note as a quick‑reference guide while studying, practising programming, or revising for the exams.

Create an account or Login to take a Quiz

88 views
0 improvement suggestions

Log in to suggest improvements to this note.