Library › Computer Science 9618 › Data Representation (A Level)
AS Level · Computer Science 9618

Data Representation (A Level)

Revise Data Representation (A Level) for Computer Science 9618 (AS Level) — revision notes and instant AI marking.

📖 Revision notes · preview
  Cambridge International AS & A Level Computer Science (9618)

Data Representation (A Level)

The big idea: Built-in types are not enough for real problems, so you define your own. Data must also live in files organised for the way it is used, and real numbers live in floating point, where range, precision and rounding are always being traded against each other.

Summary — What This Chapter Covers
  • User-defined types model the problem: non-composite (enumerated, pointer) and composite (record, set, class).
  • Serial files store records in the order they arrive; sequential files keep them in key order; random files place each record at an address calculated from its key.
  • Sequential access reads from the start; direct access goes straight to a record (sequential files with an index, random files by hashing).
  • A hashing algorithm turns a key into an address. Collisions are handled by storing in the next free slot or in an overflow area.
  • Floating point = mantissa × 2exponent, both in two's complement. A normalised positive mantissa starts 0.1; a negative one starts 1.0.
  • More mantissa bits give more precision; more exponent bits give more range.
  • Overflow: a result too large for the exponent. Underflow: a result too close to zero. Many fractions such as 0.1 can only be approximated, which causes rounding errors.
1. User-defined Data Types
13.1

Enumerated, pointer, set, record, class

A user-defined data type is one the programmer defines from the built-in types. They are needed because built-in types cannot model every problem: a type can restrict values to a sensible list, group related data under one name, or describe how data links together. This makes programs easier to read and harder to misuse.

Non-composite types (defined without reference to another type's structure)
TYPE Season = (Spring, Summer, Autumn, Winter)   // enumerated
TYPE TIntPointer = ^INTEGER                      // pointer to an INTEGER

DECLARE ThisSeason : Season
DECLARE MyPointer : TIntPointer
DECLARE Number : INTEGER
ThisSeason ← Summer
MyPointer ← ^Number          // MyPointer holds the address of Number
MyPointer^ ← 42              // stores 42 in Number (dereferencing)

An enumerated type lists every value the variable may take; the values are ordered, so Autumn > Summer is TRUE. A pointer type holds a memory address of data of the stated type; ^Number gives the address and MyPointer^ reads or writes the value at that address.

Composite types (built from other types)
TYPE Book                              // record
   DECLARE ISBN : STRING
   DECLARE Title : STRING
   DECLARE Price : REAL
   DECLARE OnLoan : BOOLEAN
ENDTYPE

TYPE LetterSet = SET OF CHAR           // set
DEFINE Vowels ('A', 'E', 'I', 'O', 'U') : LetterSet

DECLARE Library : ARRAY[1:500] OF Book
Library[1].Title ← "Hard Times"

A record groups fields of different types about one thing. A set holds an unordered collection of distinct values and supports operations such as membership, union and intersection. A class (see chapter 20) groups data and the methods that act on it; an object is an instance of a class.

Worked Example
A hotel stores, for each room, its number, its type (single, double or suite), the nightly rate and whether it is occupied. Design suitable user-defined types in pseudocode.
Memorise
🔓 Read the full Data Representation (A Level) note → You're seeing the preview · sign in to read it all
Also in the full note
  • Serial, sequential, random and hashing
  • Mantissa, exponent and normalisation
What's inside
📖 Revision notes 🎯 Learn mode ✦ AI flashcards ✓ Instant AI marking 🧊 3D explorers 🧪 Experiments & simulations 📈 Progress tracking
📄 Practise Data Representation (A Level) with Computer Science 9618 past papers Every paper with its mark scheme — answer online, marked instantly. Open →

Read the full Data Representation (A Level) notes free

That's the preview — create a free account to read the rest, plus flashcards and practice questions with instant AI marking. No credit card.

Unlock the full notes free →

More Computer Science topics