IB Computer Science B2.2: Data structures
New IB Computer Science syllabus · first exams May 2027 · Theme B · Paper 2 · SL & HL · Python and Java
Choosing a data structure is a design decision, not just a syntax choice. B2.2 covers fixed and growable structures, and two structures that deliberately restrict how data goes in and out: stacks and queues.
| Statement | Topic | Command term |
|---|---|---|
| B2.2.1 | Static vs dynamic data structures | Compare |
| B2.2.2 | Arrays and Lists | Construct |
| B2.2.3 | Stacks (LIFO) | Explain |
| B2.2.4 | Queues (FIFO) | Explain |
Key points
B2.2.1 Static vs dynamic
- Static (an array): memory is allocated once, at a fixed size. It's fast and predictable, but it can't grow. To grow it, you have to create a bigger array and copy the data across.
- Dynamic (a list): grows and shrinks automatically, with its storage reallocated behind the scenes. It's flexible, but has some overhead.
- Compare them on speed, memory use and flexibility.
B2.2.2 Arrays and Lists
- Java: 1D and 2D arrays, and
ArrayList. - Python: 1D and 2D lists.
- You must be able to add, remove and traverse elements in a dynamic list.
- A 2D structure is indexed as
[row][col].
B2.2.3 Stacks: last in, first out
- Operations:
push,pop,peek,isEmpty. - Uses: undo features, browser history, call stacks.
B2.2.4 Queues: first in, first out
- Operations:
enqueue,dequeue,front,isEmpty. - Uses: printer queues, task scheduling.
- Always check
isEmptybeforedequeue, to avoid a runtime error.
Exam-style question
Trace the contents of an initially empty stack after the following operations, showing the contents after each step: push(5), push(8), pop(), push(3), peek(). [5]
Mark scheme
[1] per correct step:
| Operation | Stack (bottom → top) | Returns |
|---|---|---|
push(5) | [5] | n/a |
push(8) | [5, 8] | n/a |
pop() | [5] | 8 |
push(3) | [5, 3] | n/a |
peek() | [5, 3] (unchanged) | 3 |
Common mistakes that cost marks
- Thinking
peekremoves the item. It only looks at the top item. - Mixing up LIFO and FIFO in scenario questions. An undo feature needs a stack; a print queue needs a queue.
- Indexing the centre of a 3×3 grid as
[2][2]. It's[1][1], because indexes start at 0.
Frequently asked questions
Do Java students need ArrayList?
Yes. The guide names 1D arrays, 2D arrays and ArrayLists for Java, and 1D and 2D lists for Python.
Which stack and queue operations must I know?
Stacks: push, pop, peek and isEmpty. Queues: enqueue, dequeue, front and isEmpty.
Go further
- Practise B2.2 with instant marking on ExamHaus, in Python or Java. → examhaus.com
- Full B2.2 presentation and question bank with mark scheme on CS Exam Ready. → csexamready.com/resources/ib-diploma
- IB CS mock exams: Paper 2 in Python and Java. → examhaus.com/mock-exams
