Published by Patrick Mutisya · 14 days ago
An Abstract Data Type (ADT) defines a data structure purely by the operations that can be performed on it and the mathematical properties of those operations. The implementation details (e.g., arrays, linked nodes) are hidden from the user.
A stack follows the Last‑In‑First‑Out (LIFO) principle. The primary operations are:
push(x) – add element x to the top.pop() – remove and return the top element.peek() – view the top element without removing it.isEmpty() – test whether the stack contains no elements.Typical use‑cases include expression evaluation, back‑tracking algorithms, and function call management.
A queue follows the First‑In‑First‑Out (FIFO) principle. Core operations are:
enqueue(x) – add element x to the rear.dequeue() – remove and return the front element.front() – view the front element without removing it.isEmpty() – test whether the queue is empty.Queues are used in scheduling, breadth‑first search, and buffering data streams.
A linked list consists of nodes, each containing data and a reference (link) to the next node. Variants include:
Common operations:
insert(pos, x) – insert element x at position pos.delete(pos) – remove element at position pos.search(x) – locate the first occurrence of x.traverse() – visit each element in order.| Feature | Stack | Queue | Linked List |
|---|---|---|---|
| Access Order | LIFO | FIFO | Sequential (as defined by links) |
| Typical Operations | push, pop, peek | enqueue, dequeue, front | insert, delete, search, traverse |
| Implementation Options | Array or linked list | Array (circular buffer) or linked list | Node objects with pointers |
| Memory Use | Fixed (array) or dynamic (linked) | Fixed (array) or dynamic (linked) | Dynamic – one node per element |
| Common Applications | Expression evaluation, recursion | Print queues, task scheduling | Dynamic collections, adjacency lists |
Suppose we need to store the sequence of integers entered by a user and later retrieve them in reverse order.
n, execute stack.push(n).stack.pop() until the stack is empty.queue.enqueue(n).list.insert(0, n). This builds the list in reverse order directly.The abstract behaviour of a stack can be expressed as:
\$\text{push}(S, x) = S \cup \{(top+1, x)\}\$
\$\$\text{pop}(S) = \begin{cases}
(S', x) & \text{if } S = S' \cup \{(top, x)\} \\
\text{error} & \text{if } S = \emptyset
\end{cases}\$\$
Similarly, a queue’s enqueue operation can be described by:
\$\text{enqueue}(Q, x) = Q \cup \{(rear+1, x)\}\$
Understanding ADTs allows you to choose the most appropriate data structure for a given problem, focusing on the operations required rather than the underlying implementation. Stacks, queues, and linked lists each provide distinct access patterns and performance characteristics, making them fundamental tools in algorithm design.