Properties and purpose of ADTs in programming
Explain the properties and purpose of ADTs in programming
In this lesson
- Describing an ADT as a set of values and the operations on them, independent of how it is implemented
- Distinguishing an ADT’s interface (what it does) from its implementation (how it does it)
- Explaining the properties of ADTs: defined operations, abstraction, encapsulation, modularity and reusability
- Explaining why programmers use ADTs
LearnWhat, not how
LearnCommon ADTs and their operations
| ADT | Behaviour | Access | Insertion | Deletion |
|---|---|---|---|---|
| List | Items in a sequence, each at a position | get(i) | add(item), insert(i, item) | remove(i) |
| Stack | Last in, first out (LIFO) | peek() | push(item) | pop() |
| Queue | First in, first out (FIFO) | peek() | enqueue(item) | dequeue() |
| Set | Distinct items, no order | contains(item) | add(item) | remove(item) |
| Map (dictionary) | Each key is linked to one value | get(key) | put(key, value) | remove(key) |
Most ADTs also have operations such as isEmpty() and size(). The names vary between languages and libraries; the behaviour is what defines the ADT.
LabSame queue, different insides
The program on the left only calls the queue’s operations. On the right you can look inside two different implementations of the same Queue ADT.
The program (uses only the operations)
Use the buttons above.
Output:
Inside the Queue (hidden from the program)
- [0]·
- [1]·
- [2]·
- [3]·
front = 0, count = 0, capacity = 4
- Not done: Enqueue at least two items and dequeue one
- Not done: After a few operations, switch the implementation and compare the program and its output
- Not done: Fill the array implementation so that it has to grow, and look inside it
CodeOne interface, two implementations
Ana Ben | next: Cy | empty: True Ana Ben | next: Cy | empty: True
Queue lists the operations. ArrayQueue and LinkedQueue carry them out in completely different ways, but serve is written only in terms of the operations, so it gives the same output with either. Their attributes are private, so no other code can disturb the order of the queue.
CheckInterface or implementation?
Does each statement describe the Queue ADT (what any queue does) or one particular implementation (how it does it)?
- dequeue() removes and returns the item that has waited longest
- The items are kept in an array with a front index that wraps round
- peek() returns the front item without removing it
- When the array is full, its contents are copied into one twice the size
- Each item is stored in a node that refers to the node behind it
- isEmpty() returns true when there are no items
CheckQuick check
A program needs a print queue in which jobs must never be able to jump ahead of others. How does using a Queue ADT help to guarantee this?
ExamWorked exam answer
A team is adding an undo feature to a text editor and decides to use a Stack ADT. Explain how using the ADT helps the team to develop the feature.
[3]ReviewMistakes examiners see
Treating an ADT and a data structure as the same thing: a queue (ADT) can be implemented with an array or a linked list (data structures).
Defining an ADT only as “a data type made by the programmer”, without mentioning its operations.
Listing properties such as “encapsulation” without saying what they mean for the scenario in the question.
In explanations, link the property to its effect: e.g. encapsulation → data can only change through the operations → it cannot be put into an invalid state.
Exam practiceExam-style questions
3 questions · 7 marks. Answer each one first, then mark it yourself against the markscheme. Your answers are saved in this browser only.
A school’s printing system receives print jobs from many computers and sends them to a single printer. The jobs are held in a Queue ADT. At present the queue is implemented with a fixed-size array of 50 jobs, which fills up on busy days.
Outline why a queue, rather than a stack, is the appropriate ADT for the print jobs.
The developers replace the fixed-size array with an implementation that can grow. Explain why the rest of the printing system does not need to be changed.
A teacher asks for a feature that would let any computer move its own job to the front of the queue. Explain how the use of the Queue ADT prevents this from being added without the developers’ agreement.
0 of 3 questions marked. Mark every question to see your total.
Exam-style questions written for Praxis IB in the format of the 2027 specimen papers. They are not IB past-paper questions.