Data Structures
IB Syllabus: B2.2 — Data structures
Overview
Every program needs to store collections of data. This section covers the fundamental data structures you need for IB Computer Science — from simple arrays to abstract structures like stacks and queues.
| Structure | Type | Key Feature | Syllabus |
|---|---|---|---|
| 1D Arrays | Static | Fixed size, direct index access | B2.2.2 |
| 2D Arrays | Static | Rows and columns (grid/table) | B2.2.2 |
| ArrayList | Dynamic | Grows/shrinks automatically | B2.2.3 |
| Stacks | Abstract | Last In, First Out (LIFO) | B2.2.4 |
| Queues | Abstract | First In, First Out (FIFO) | B2.2.5 |
Sub-pages with full worked examples, quizzes, and exercises are being built out. 2D Arrays is the first complete sub-page — the rest will follow soon.
Choosing the Right Structure
| Situation | Best choice |
|---|---|
| Fixed number of items, fast index access | Array |
| Number of items changes at runtime | ArrayList |
| Need LIFO (undo, backtracking) | Stack |
| Need FIFO (order matters, job queue) | Queue |
| Tabular data (grid, board, matrix) | 2D Array |
Static vs Dynamic Structures
| Feature | Static (Array) | Dynamic (ArrayList, Stack, Queue) |
|---|---|---|
| Size | Fixed at creation | Grows or shrinks at runtime |
| Memory | Allocated once | Allocated as needed |
| Access | Direct by index | Depends on type |
| Speed | Very fast | Slight overhead |
The key insight: static structures are simpler and faster when you know the size in advance. Dynamic structures are necessary when size changes at runtime.