An Abstract Data Type (ADT) defines a data structure solely by its behaviour – the operations that can be performed on it and the mathematical properties of those operations. The concrete way the data are stored in memory is deliberately hidden (information hiding).
When an ADT is specified we give:
ADT Stack
Operations:
push(x) – pre: true;
post: top = x, size = size + 1; O(1)
pop() – pre: !isEmpty();
post: returns former top, size = size – 1; O(1)
top() – pre: !isEmpty();
post: returns current top; O(1)
isEmpty() – pre: true;
post: returns true iff size = 0; O(1)
Abstract State:
sequence S = ⟨⟩ (initially empty)
| ADT | Typical Operations (signature) | Typical Implementations |
|---|---|---|
| Stack |
|
Fixed‑size array, dynamic array, singly linked list |
| Queue |
|
Circular array, doubly linked list |
| List (Sequence) |
|
Dynamic array (e.g., Python list), doubly linked list |
| Map (Associative Array) |
|
Hash table, binary search tree (BST), balanced tree (AVL/Red‑Black) |
| Set |
|
Hash set, BST, bit‑vector |
| Priority Queue |
|
Binary heap, d‑ary heap, balanced BST |
The pseudo‑code below follows the specification in Section 4 while using a fixed‑size array. It demonstrates information hiding – the client can only call the four public operations.
CONST MAX = 100
TYPE StackArray
data: array[0..MAX‑1] of integer
topIndex: integer ← -1 // -1 indicates an empty stack
PROCEDURE push(S: StackArray, x: integer)
IF S.topIndex = MAX‑1 THEN
ERROR "Stack overflow"
END IF
S.topIndex ← S.topIndex + 1
S.data[S.topIndex] ← x
END PROCEDURE
FUNCTION pop(S: StackArray) RETURNS integer
IF S.topIndex = -1 THEN
ERROR "Stack underflow"
END IF
x ← S.data[S.topIndex]
S.topIndex ← S.topIndex - 1
RETURN x
END FUNCTION
FUNCTION top(S: StackArray) RETURNS integer
IF S.topIndex = -1 THEN
ERROR "Stack empty"
END IF
RETURN S.data[S.topIndex]
END FUNCTION
FUNCTION isEmpty(S: StackArray) RETURNS boolean
RETURN S.topIndex = -1
END FUNCTION
| Operation | Array Implementation | Linked‑List Implementation |
|---|---|---|
| push | O(1) (amortised O(1) if dynamic resizing) | O(1) |
| pop | O(1) | O(1) |
| top | O(1) | O(1) |
| isEmpty | O(1) | O(1) |
Problem: Given a string consisting of ( ) [ ] { }, determine whether the brackets are correctly balanced.
Required ADT: Stack
s of length n.S.c in s:
c is an opening symbol (, [ or {, execute push(S, c).c is a closing symbol:
isEmpty(S) → string is unbalanced (stop).t ← pop(S) and check that t matches c (e.g. ( matches )). If not, the string is unbalanced (stop).isEmpty(S) is true.Complexity analysis
| Syllabus Requirement | Covered in These Notes? | Action Needed |
|---|---|---|
| Define an ADT and explain encapsulation | ✅ | – |
| Specify an ADT using signature, pre‑/post‑conditions and complexity | ✅ (Stack example) | – |
| Provide at least three concrete implementations of the same ADT | ✅ (array vs. linked‑list stack, table of implementations) | – |
| Analyse time and space complexity of each implementation | ✅ (complexity table + exercise analysis) | – |
| Use an ADT in a non‑trivial algorithm and justify the choice | ✅ (balanced‑brackets algorithm) | – |
| Discuss other ADTs (Queue, Map, Set, Priority Queue) and give example applications | ✅ (Section 8) | – |
| Include a worked example of an ADT implementation in pseudo‑code | ✅ (array‑based Stack) | – |
| Reference the Cambridge “formal specification” style | ✅ (Section 4) | – |
If any row shows a ❌, add the missing material before using these notes for revision.
Create an account or Login to take a Quiz
Log in to suggest improvements to this note.
Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.