Data structures

Study Part 2 · Topic 3 of 5

Arrays, records, files, stacks, queues and trees: how data is organised for fast use.

30 minInteractiveData storage and IT in the organisation
0 activities complete
Structures

Organising data

Array

A list of values of the same type, each found by its position (index).

Record

A group of related fields about one thing: name, ID, department.

File

A collection of records stored on disk, such as a staff file.

Stack

Last in, first out (LIFO): like a stack of plates or the Undo button.

Queue

First in, first out (FIFO): like a print queue or a call queue.

Tree

A hierarchy of parent and child items, such as folders on a drive.

Watch a stack work
1

Push A

Stack: A

2

Push B

Stack: A, B

3

Push C

Stack: A, B, C

4

Pop

C comes off first. Stack: A, B. This is why Undo removes your most recent change first.

Watch a queue work
1

Job 1 arrives

Print queue: Job 1

2

Job 2 arrives

Print queue: Job 1, Job 2

3

Job 3 arrives

Print queue: Job 1, Job 2, Job 3

4

Printer takes the next job

Job 1 prints first. The queue keeps the order fair.

Stack, queue or tree?

Choose the right group for each item. 6 left to sort

Callers waiting for the help desk
Folders and sub-folders on a server
Documents waiting to print
An organisation chart
Undo in Word
The browser Back button history
Files

How records are accessed

Records are read one after another from the start, like a cassette tape. Good for payroll runs.

Any record can be read immediately using its key or address, like a song on a playlist. Good for lookups.

An index points to where each record is stored, like the index at the back of a book. Databases use indexes for speed.

Knowledge check

Which structure works on a first in, first out basis?

Key takeaways

  • Arrays, records and files organise related data.
  • Stacks are LIFO, queues are FIFO, trees are hierarchies.
  • Files can be accessed sequentially, directly or through an index.