top, front, rear, head, free) are needed to give the array the behaviour of a stack, queue or (static) linked list.| AO | What the examiner looks for |
|---|---|
| AO1 | Recall definitions – ADT, LIFO, FIFO, static linked list, overflow, underflow. |
| AO2 | Explain how the array implementation works, interpret pseudocode, and discuss time‑complexity. |
| AO3 | Design, write and trace correct pseudocode or Java/Python code; analyse correctness and efficiency. |
A stack stores items so that the most recently added item is the first to be removed.
stack[0 … N‑1]top – index of the current top element (‑1 when empty)INTEGER top ← -1 // empty stack INTEGER N ← size of stack // maximum capacity
| Operation | Pseudocode | Time complexity |
|---|---|---|
| Push(value) |
PROCEDURE Push(value)
IF top = N‑1 THEN
DISPLAY "Stack overflow"
RETURN
ENDIF
top ← top + 1
stack[top] ← value
END PROCEDURE
|
O(1) |
| Pop() |
FUNCTION Pop() RETURNS INTEGER
IF top = -1 THEN
DISPLAY "Stack underflow"
RETURN -1 // sentinel
ENDIF
value ← stack[top]
top ← top - 1
RETURN value
END FUNCTION
|
O(1) |
| Peek() |
FUNCTION Peek() RETURNS INTEGER
IF top = -1 THEN
DISPLAY "Stack empty"
RETURN -1
ENDIF
RETURN stack[top]
END FUNCTION
|
O(1) |
Push the values 5, 8, 3 onto a stack of size 5, then pop twice.
top = 2, stack = [5,8,3,_,_]top = 1top = 0top = N‑1 *before* inserting – prevents writing past the array.top = 0 as the empty condition (the correct sentinel is -1).A queue removes items in the same order they were added.
queue[0 … N‑1]front (position of first element) and rear (position for next insertion)size to distinguish empty from full.INTEGER front ← 0 INTEGER rear ← 0 INTEGER size ← 0 INTEGER N ← size of queue
| Operation | Pseudocode | Time complexity |
|---|---|---|
| Enqueue(value) |
PROCEDURE Enqueue(value)
IF size = N THEN
DISPLAY "Queue overflow"
RETURN
ENDIF
queue[rear] ← value
rear ← (rear + 1) MOD N
size ← size + 1
END PROCEDURE
|
O(1) |
| Dequeue() |
FUNCTION Dequeue() RETURNS INTEGER
IF size = 0 THEN
DISPLAY "Queue underflow"
RETURN -1
ENDIF
value ← queue[front]
front ← (front + 1) MOD N
size ← size - 1
RETURN value
END FUNCTION
|
O(1) |
| Peek() |
FUNCTION Peek() RETURNS INTEGER
IF size = 0 THEN
DISPLAY "Queue empty"
RETURN -1
ENDIF
RETURN queue[front]
END FUNCTION
|
O(1) |
Enqueue 10, 20, 30 into a queue of size 4, then dequeue twice.
front = 0, rear = 3, size = 3, queue = [10,20,30,_]front = 1, size = 2front = 2, size = 1front = rear alone to test emptiness – you cannot tell full from empty without a size counter or a “one slot empty” rule.front or rear – leads to index‑out‑of‑range errors.size before moving the pointer (or vice‑versa) – causes off‑by‑one bugs.A static (or “array‑based”) linked list replaces dynamic memory allocation with two parallel arrays:
data[0 … N‑1] – stores the actual values.next[0 … N‑1] – stores the index of the next node; -1 denotes “null”.A head variable points to the first logical node, and a free list (implemented as a stack of unused indices) manages allocation.
PROCEDURE InitialiseStaticList()
FOR i ← 0 TO N‑1 DO
next[i] ← i + 1 // build free list
ENDFOR
next[N‑1] ← -1 // end of free list
head ← -1 // logical list empty
free ← 0 // first free cell
END PROCEDURE
PROCEDURE InsertHead(value)
IF free = -1 THEN
DISPLAY "Static list overflow"
RETURN
ENDIF
newNode ← free // take first free cell
free ← next[free] // remove it from free list
data[newNode] ← value
next[newNode] ← head
head ← newNode
END PROCEDURE
FUNCTION DeleteHead() RETURNS INTEGER
IF head = -1 THEN
DISPLAY "Static list underflow"
RETURN -1
ENDIF
delNode ← head
head ← next[head] // advance head
value ← data[delNode] // optional return
next[delNode] ← free // return node to free list
free ← delNode
RETURN value
END FUNCTION
FUNCTION Search(target) RETURNS INTEGER
index ← head
WHILE index ≠ -1 DO
IF data[index] = target THEN
RETURN index // found
ENDIF
index ← next[index]
ENDWHILE
RETURN -1 // not found
END FUNCTION
PROCEDURE InsertAfter(pos, value)
IF pos = -1 THEN // treat as InsertHead
InsertHead(value)
RETURN
ENDIF
IF free = -1 THEN
DISPLAY "Static list overflow"
RETURN
ENDIF
newNode ← free
free ← next[free]
data[newNode] ← value
next[newNode] ← next[pos]
next[pos] ← newNode
END PROCEDURE
PROCEDURE DeleteNode(pos)
IF head = -1 OR pos = -1 THEN
DISPLAY "Invalid delete"
RETURN
ENDIF
IF pos = head THEN
CALL DeleteHead()
RETURN
ENDIF
// find predecessor
pred ← head
WHILE pred ≠ -1 AND next[pred] ≠ pos DO
pred ← next[pred]
ENDWHILE
IF pred = -1 THEN
DISPLAY "Node not found"
RETURN
ENDIF
next[pred] ← next[pos] // bypass node
next[pos] ← free // return to free list
free ← pos
END PROCEDURE
| Operation | Time complexity |
|---|---|
| Insert at head | O(1) |
| Delete at head | O(1) |
| Insert after a known position | O(1) |
| Delete a known position (with predecessor search) | O(n) in worst case |
| Search by value | O(n) |
free after an insertion – leads to “memory leaks” inside the static list.-1 both for “null” and for a legitimate array index – initialise head and free correctly.head *before* returning the node to the free list; otherwise the list can become corrupted.| ADT | Operation | Array implementation | Time complexity |
|---|---|---|---|
| Stack | Push | Increment top, store at stack[top] |
O(1) |
| Pop | Return stack[top], decrement top |
O(1) | |
| Peek | Read stack[top] without changing top |
O(1) | |
| Queue | Enqueue | Store at queue[rear], advance rear circularly, size←size+1 |
O(1) |
| Dequeue | Read queue[front], advance front circularly, size←size‑1 |
O(1) | |
| Peek | Read queue[front] without moving pointers |
O(1) | |
| Size | Maintain integer size |
O(1) | |
| Static Linked List | Insert at head | Allocate from free list, set next[new] = head, head = new |
O(1) |
| Delete at head | Update head, return old node to free list |
O(1) | |
| Search (by value) | Traverse next chain from head |
O(n) | |
| Insert/Delete at arbitrary position | Traverse to predecessor, adjust two next entries |
O(n) |
| Syllabus unit | Relevant notes above | Exam relevance (AO) |
|---|---|---|
| 1.1 Information representation (binary, hexadecimal, BCD) | Background for array indexing and overflow handling – add a short conversion worksheet. | AO1, AO2 |
| 2.2 Data types & structures (arrays, records, files) | Full coverage of array‑based ADTs (stack, queue, static linked list). | AO1‑AO3 |
| 4.1 Algorithms – analysis of time complexity | Complexity tables for each operation. | AO2, AO3 |
| 5.2 Recursion (A‑Level) | Use the static linked list as a basis for recursive traversal examples (e.g., recursive search). | AO2, AO3 |
| 7.1 Software development – testing & maintenance (Paper 4) | Practical lab (see Section 8) includes test‑case design and debugging of overflow/underflow. | AO3 |
| 8.2 Data structures – dynamic structures (A‑Level) | Static linked list introduces the idea of “next” pointers before moving to true dynamic linked lists. | AO2, AO3 |
Students should complete the following lab in Java (or Python) and submit the source code with a short test report.
ArrayStack with methods push, pop, peek.CircularQueue using a circular buffer.data[] and next[] inside a class StaticList.insertHead, deleteHead, search, and insertAfter.IF … THEN … ENDIF, separate PROCEDURE/FUNCTION blocks) and always state the time complexity of each operation.top arrow pointing to the last filled cell.front and rear positions, with arrows indicating the direction of movement.data and next) with arrows linking indices, plus separate arrows for head and free pointers.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.