An Abstract Data Type (ADT) is a mathematical description of a collection of values together with the operations that can be performed on that collection. The description tells what the data are and what each operation does, but it does not prescribe how the operations are implemented.
push, pop, add, remove).For each ADT we give:
Set never contains duplicate elements).| ADT | Operations (signature) | Behaviour (informal description) | Typical error condition |
|---|---|---|---|
| Stack |
push(value: T) → voidpop() → Tpeek() → TisEmpty() → boolean
|
Last‑In‑First‑Out. push adds an element to the top; pop removes and returns the top element; peek returns the top element without removing it. |
Under‑flow – calling pop or peek when isEmpty() = true. |
| Queue |
enqueue(value: T) → voiddequeue() → Tfront() → TisEmpty() → boolean
|
First‑In‑First‑Out. Elements are added at the rear and removed from the front. | Under‑flow – calling dequeue or front on an empty queue. |
| List (array‑based or linked) |
insert(index: int, value: T) → voidremove(index: int) → Tget(index: int) → Tsize() → int
|
Ordered collection with random indexed access. | Index‑out‑of‑range (negative or ≥ size()). |
| Set |
add(value: T) → voidremove(value: T) → voidcontains(value: T) → booleansize() → int
|
Unordered collection of **unique** elements. | None – adding a duplicate leaves the set unchanged (invariant: no duplicates). |
| Map (Dictionary) |
put(key: K, value: V) → voidget(key: K) → Vremove(key: K) → VcontainsKey(key: K) → boolean
|
Associates each unique key with a value. | Key‑not‑found – calling get or remove with a key that is not present. |
Let S be the current stack state, represented as an ordered sequence [s₁, s₂, …, sₙ] where sₙ is the top element. For a value v:
push(S, v) = [s₁, …, sₙ, v]n ≥ 1.pop(S) = (v, S') where v = sₙ and S' = [s₁, …, sₙ₋₁].n ≥ 1.peek(S) = sₙisEmpty(S) = (n = 0)TYPE Stack
ARRAY data[0..MAX-1] OF INTEGER
INTEGER top ← -1 // -1 indicates an empty stack
END TYPE
FUNCTION push(s: REF Stack, v: INTEGER) → VOID
IF s.top = MAX-1 THEN
ERROR "Stack overflow"
ELSE
s.top ← s.top + 1
s.data[s.top] ← v
END IF
END FUNCTION
FUNCTION pop(s: REF Stack) → INTEGER
IF s.top = -1 THEN
ERROR "Stack under‑flow"
END IF
v ← s.data[s.top]
s.top ← s.top - 1
RETURN v
END FUNCTION
FUNCTION peek(s: REF Stack) → INTEGER
IF s.top = -1 THEN
ERROR "Stack under‑flow"
END IF
RETURN s.data[s.top]
END FUNCTION
FUNCTION isEmpty(s: REF Stack) → BOOLEAN
RETURN s.top = -1
END FUNCTION
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.