13 Advanced data representation
Design user-defined types, choose file organisation and access, apply hashing, and reason about floating-point limits.
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 type restricts values to a predefined list of names?
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
User-defined types encode domain meaning
An enumerated type restricts a value to named alternatives. A pointer stores a reference to another value or structure. Composite types combine data: a set holds distinct members; a record groups named fields; a class describes objects with state and behaviour.
Select a type by the operations and constraints of the problem. A well-designed type can make invalid states harder to represent, but the program still needs validation and defined behaviour for missing or inconsistent data.
Files and floating point require explicit limits
Serial files store records in arrival order without a key ordering; sequential files are ordered by a key; random files use a record key or location for direct access. Hashing maps a key to a storage location; collisions need a resolution strategy and a table's load factor affects performance.
Floating-point values store a sign, exponent and mantissa/significand with finite precision. Rounding can cause small representation errors, and limited exponent range can cause underflow or overflow. Compare approximate values with a tolerance where exact equality is not reliable.
Pause and explain
Why compare floating-point results using a tolerance?
Worked example
A file has customer records keyed by CustomerID and must find one record quickly. Compare sequential-by-key and random access.
Show the worked solution
- Sequential access reads records in order until the key is found.
- Random access uses a key or calculated location to reach a record directly, subject to the organisation and index.
- The best choice depends on update patterns and storage requirements.
Answer Random access can retrieve a keyed record without scanning every earlier record; sequential access is simpler for ordered batch processing.
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 system has status values Draft, Active and Archived. Propose a user-defined type and explain one advantage.
Give me a hint
These values form a fixed named set.
Compare my reasoning
- Define an enumeration containing Draft, Active and Archived.
- Assign status variables only values from the declared alternatives.
- This improves readability and can prevent arbitrary status strings.
Use an enumerated type; its named alternatives make allowed states explicit.
Look for these in your work
- Enumeration chosen
- Values represented
- Constraint benefit stated
A program hashes an account number to a table location, but two accounts map to the same index. What has happened and name a resolution approach.
Give me a hint
A hash maps keys to slots; distinct keys can share a slot.
Compare my reasoning
- A collision occurred.
- One approach is chaining entries at the same bucket.
- Another is open addressing, which searches for another available slot.
A collision occurred; use chaining or open addressing.
Look for these in your work
- Collision named
- Resolution described
- Different keys distinguished
A calculation compares 0.1 + 0.2 with 0.3 in floating-point arithmetic. Explain why exact equality may fail and how to compare robustly.
Give me a hint
Consider the finite binary representation of decimal fractions.
Compare my reasoning
- Some decimal fractions cannot be represented exactly with a finite binary mantissa.
- Rounding may produce a small difference between the calculated and stored values.
- Compare the absolute difference with a chosen tolerance appropriate to the calculation.
Use a tolerance such as |a−b| < ε, choosing ε for the problem's scale and required precision.
Look for these in your work
- Representation limit explained
- Rounding effect identified
- Tolerance comparison applied
Common mistakes
- Treating a hash function as collision-proof.
- Assuming floating-point decimal values are always represented exactly.
- Confusing serial arrival order with sequential key order.
What can you explain now?
Why can two different keys require collision handling in a hash table?
Compare with the explanation
Different inputs can map to the same storage location.
A hash function may produce the same index for distinct keys, so the implementation needs a collision strategy.
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 user-defined types, file organisation, hashing and floating-point representation shape a data design?
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.