B.4 Abstract data types · HL
Implement stacks and queues
Separate an abstract interface from its representation and handle empty or full states.
Examples use Python. HL includes additional lessons beyond the SL path.
Define behavior before storage
A stack removes the most recently added item first. A queue removes the earliest added item first. These rules define observable behavior, not a particular array or linked representation. Clients use the operations without relying on where the values are stored.
A bounded array stack can use a top index. Push must check capacity before increasing top; pop must check whether the stack is empty before reading. Decide what the caller receives on failure rather than returning a value indistinguishable from stored data.
Trace a circular queue
A circular queue reuses space by wrapping its front and rear indices. With capacity 4, advancing an index can use (index + 1) % 4. A count of stored elements can distinguish empty from full even when the indices coincide.
For enqueue A, enqueue B, dequeue, enqueue C, a queue removes A and leaves B before C. A stack with the corresponding push and pop operations would remove B. Use the order requirement to justify the data type.
Check yourself
Which structure naturally represents jobs waiting in arrival order?Show answer
A queue, because it is first in, first out.
References used to build these lessons
We used these official documents as references when building this course's lessons. They are the sources for the syllabus structure and course requirements.
International Baccalaureate · First assessment 2027
This PDF is the public IB subject brief. The complete subject guide and assessment requirements are available through your school or the IB Programme Resource Centre.