Introduction to Abstract Data Types (ADT)

Computer Science AS · Data types and structures. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science AS topics

The idea

An abstract data type is a collection of data and a set of operations on that data. It says what can be done with the data, not how the data is stored.

A stack is last in, first out: items are added and removed at the same end, the top. A queue is first in, first out: items join at the rear and leave from the front. A linked list is a chain of nodes. Each node holds data and a pointer to the next node, so an item is inserted or deleted by changing pointers and no data is moved.

All three can be built from arrays together with integer variables used as pointers.

Rules to remember

Common mistake

Removing from the wrong end. A queue gives up its oldest item and a stack gives up its newest item. Write down the contents after every operation.

Worked example

The values 4, 9 and 2 are added, in that order, to an empty stack and also to an empty queue. Two items are then removed from each. Which item is left in each structure?

  1. Stack: 2 was pushed last, so it is popped first, then 9. The item 4 is left.
  2. Queue: 4 joined first, so it leaves first, then 9. The item 2 is left.

Answer: The stack holds 4 and the queue holds 2.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← FilesProgramming basics →Take a Computer Science AS test