10 Data types and structures
Select suitable scalar and structured data types, process arrays and files, and model stacks, queues and linked lists.
Mapped to Cambridge International AS & A Level Computer Science 9618, 2027–2029 Version 2. These original lessons and self-checks are independent study support; they are not Cambridge papers, official marks or grades. The course does not yet provide a timed four-paper simulation or a locked-down Paper 4 programming environment.
Before you begin
- Use the 2027–2029 syllabus for your exam year. AS candidates study Sections 1–12; A Level candidates study Sections 1–20. Paper 4 uses a programming language chosen from Python, Java or Visual Basic in console mode.
Work on paper. Try each question before revealing help, and explain why your method works.
Quick readiness check
Which structure is FIFO?
What you will learn
- Explain the key representations, structures or processes in this syllabus section
- Apply the method to a new computer-science example
- Justify a design choice and check its limits
Choose a type that matches the value and operations
INTEGER stores whole numbers; REAL stores values with fractional parts; CHAR holds one character; STRING holds text; BOOLEAN holds TRUE or FALSE; DATE represents a calendar date. An array stores multiple values of one type; a record groups named fields that may have different types.
A file preserves data beyond a program run. Sequential access reads records in order; random access can move directly to a record when its location or key is known. File operations should handle end-of-file and invalid records safely.
Abstract data types define behaviour
A stack is last in, first out (LIFO): push adds to the top and pop removes from the top. A queue is first in, first out (FIFO): enqueue adds at the rear and dequeue removes from the front.
A linked list stores data with links to other nodes. Arrays can implement stacks and queues using indices and a pointer, and can implement linked lists using an array of records with a next index. Check capacity and empty conditions before operations.
Pause and explain
Why can a record be a better choice than a parallel set of arrays for one learner?
Worked example
A queue contains 12 then 19, with 12 at the front. Enqueue 25, then dequeue once. What remains?
Show the worked solution
- Enqueue adds 25 at the rear: 12, 19, 25.
- Dequeue removes the front item, 12.
- The queue still serves the earliest remaining item first.
Answer 19, 25, with 19 at the front.
Try a topic test
Choose Easy, Normal or Difficult. Save your answers and open worked review after finishing.
Test this topic →From guided practice to a new situation
Write your answer and reasoning first. Use a hint only if you are stuck. The model solution is for self-checking; your written work is not automatically marked.
A stack initially contains A at the bottom and C at the top. Push D, then pop once. What remains and what item was returned?
Give me a hint
Apply last in, first out.
Compare my reasoning
- Push D, so D becomes the top.
- Pop removes and returns D.
- A and C remain in their previous order.
D is returned; A remains below C with C at the top.
Look for these in your work
- Push applied
- Pop result correct
- Remaining order correct
Select a suitable type for a learner's date of birth and a field that records whether consent is given. Explain each selection.
Give me a hint
Match a calendar value with a two-state value.
Compare my reasoning
- Use DATE for the date of birth.
- Use BOOLEAN for a consent state such as TRUE or FALSE.
- These types make the intended meaning and valid operations clearer.
DATE and BOOLEAN.
Look for these in your work
- Date type correct
- Consent type correct
- Reason provided
A small device logs readings for later analysis. Compare a fixed-size array and a sequential file for the readings, including one trade-off.
Give me a hint
Consider capacity, persistence and access pattern.
Compare my reasoning
- An array is convenient for processing a bounded set while the program runs.
- A file preserves readings after shutdown and can grow beyond one in-memory array.
- Sequential reading is simple but locating one later reading may require scanning earlier records.
Use an array for a bounded in-memory batch; use a sequential file for persistent logs, accepting slower lookup by position.
Look for these in your work
- Array role
- File persistence
- Trade-off identified
Common mistakes
- Removing from the rear of a queue.
- Treating an array as though its index begins at a fixed value without checking the pseudocode convention.
- Forgetting to guard against stack underflow or a full array-backed structure.
What can you explain now?
Which structure removes the newest item first?
Compare with the explanation
A stack
A stack is LIFO; a queue removes the oldest waiting item first.
After trying it yourself, choose your next review. This is your self-assessment.
Your review choice appears on Today. Sign in to sync it across devices.
Make it stick
How do stack, queue and linked-list behaviour differ, and what safeguards do their operations need?
If you needed the solution, close it and solve the problem again from a blank page. A correct answer is stronger when you can explain the reason for each step.