Computer Science · Theme B: Computational thinking and problem-solving
B2.2 — Data structures
Computer Science · SL / HL · syllabus-mapped notes
CS_B2.2.1
Static versus dynamic data structures
Memory allocation and resizing, and trade-offs in speed, memory and flexibility.
Full note — freeYou must be able to compare static and dynamic data structures, including how each handles memory. Static data structure : a fixed size decided when it is created; memory is allocated once and does not resize, for example a plain array. Dynamic data structure : can grow and shrink at run time; memory is allocated and freed as needed, for example a Python List or a Java ArrayList. Underlying mechanisms Static: one contiguous block, so element access is fast and predictable, but the size cannot change. Dynamic: resizes by allocating a larger block and copying elements over when it fills up. Trade-offs (speed, memory, flexibility) Speed : static gives fast, constant-time access with no resizing cost; dynamic pays an occasional cost when it grows. Memory : static can waste space if oversized or run out if undersized; dynamic uses only what it needs but carries some overhead. Flexibility : dynamic wins when the amount of data is unknown in advance. Choose static when the size is known and fixed and speed matters; choose dynamic when the number of items varies at run time.
CS_B2.2.2
Arrays and Lists
1D and 2D arrays, ArrayLists / Lists, and adding, removing and traversing elements.
You must be able to construct programs that apply arrays and Lists. Arrays are usually fixed size; Lists (Python) and ArrayLists (Java) are dynamic. 1D and 2D structures Python : a 1D List [10, 20, 30]; a 2D List (a list of lists) for a …
CS_B2.2.3
Stacks (LIFO)
The push, pop, peek and isEmpty operations and their performance and memory impact.
You must be able to explain a stack : a last in, first out (LIFO) structure. The last item added is the first removed, like a pile of plates. Fundamental operations (must include) push : add an item to the top. pop : remove and …
CS_B2.2.4
Queues (FIFO)
The enqueue, dequeue, front and isEmpty operations and their performance and memory impact.
You must be able to explain a queue : a first in, first out (FIFO) structure. The first item added is the first removed, like people waiting in line. Fundamental operations (must include) enqueue : add an item to the back. dequeue : remove and …
