Skip to content
Cambridge AS & A Level9618

Introduction to Abstract Data Types (ADT)

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

Introduction to Abstract Data Types (ADT) notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Introduction to Abstract Data Types (ADT) notes as text: skim, search, and jump between subtopics.

~17 min read

1. What an abstract data type is

An abstract data type (ADT) is a collection of data and a set of operations on those data.

A stack, a queue and a linked list are all ADTs. Each one has its own operations: items are pushed onto and popped from a stack, but enqueued to and dequeued from a queue.

An ADT says what is stored and what can be done to it. How it is built, for example with arrays, is a separate question.

Examiner insight

“ADT terminology was often confused, for example with the description of push and pop operations being applied to a queue.” “Other ADT names and general terms such as ‘array’ were frequently seen.”

Worked example 13 marks

A stack is an Abstract Data Type (ADT).

Identify one other ADT and describe two features of the ADT.

  1. 1

    ADT: queue (a linked list is also credited) [1]

  2. 2

    Data is added at the back / end and removed from the front / start, so it works on a first in, first out basis [1]

  3. 3

    It has a front pointer and a rear pointer [1]

2. Stack

A stack adds and removes items at the same end. PUSH adds an item and POP removes one. The last item pushed is the first to be popped, and the value that has been on the stack longest is at the bottom.

A TopOfStack pointer points to the last value added. A PUSH moves it to the new item. A POP moves it back to the item below. A POP on an empty stack causes an error.

A POP does not erase the value. It stays in memory, but the pointer bypasses it.

Examiner insight

“The most common error was to not display the AAA and BBB values remaining in locations 504 and 505 respectively. This is a subtle point for candidates to understand that following a pop operation, the values remain in memory but are effectively ‘bypassed’ by the pointers.” “A common mistake was to omit the stack pointer after each group of operations, despite this being emphasised in the question.”

Worked example 14 marks

A program processes data using a stack. The TopOfStack pointer points to the last item added to the stack. The BottomOfStack pointer points to the first item on the stack. The stack grows upwards when items are added. The table shows the stack.

The following operations are performed:

```1. POP and store value in variable Data1

  1. POP and store value in variable Data2
  2. PUSH value AAA
  3. PUSH value BBB
  4. POP and discard value
  5. POP and store value in variable Data2```

Give the final state of the stack and of the variables Data1 and Data2.

Memory locationValuePointer
506
505WWWTopOfStack
504YYY
503XXX
502ZZZ
501NNN
500PPPBottomOfStack
  1. 1

    Working: Data1 = WWW, Data2 = YYY, then AAA is pushed to 504 and BBB to 505. BBB is popped and discarded, then Data2 = AAA.

  2. 2

    Locations 505 and 504 still hold BBB and AAA [1]

  3. 3

    Locations 503 to 500 are unchanged: XXX, ZZZ, NNN, PPP [1]

  4. 4

    TopOfStack points to 503 and BottomOfStack to 500, both labelled [1]

  5. 5

    Data1 = WWW and Data2 = AAA [1]

3. Queue

A queue works on a first in, first out basis. Data is added at the end and removed from the front. It uses two pointers: a front pointer to the next item to be removed and an end pointer to the last item added.

In a circular queue the locations are reused. When the end pointer passes the last location, it wraps round to location 0. Items already in the queue never move.

Before an item is added, check that the queue is not full. Before one is removed, check that it is not empty. If the front and end pointers hold the same value, there is one item in the queue.

Examiner insight

“A common mistake was to suggest that existing queue contents would have to be moved or removed before the new data items could be added.” “References to push and pop operations were commonly seen, suggesting confusion between different ADTs.”

Worked example 14 marks

A program stores data in a text file. When data is read from the file, it is placed in a queue. The queue holds a maximum of 10 data items. The Front of Queue Pointer points to the next data item to be removed. The End of Queue Pointer points to the last data item added. The queue is circular so that locations can be reused. The table shows the queue.

Describe how the data items Orange and Yellow are added to the queue.

LocationDataPointer
0
1
2
3
4
5RedFront of Queue Pointer
6Green
7Blue
8PinkEnd of Queue Pointer
9
  1. 1

    Check that the queue is not full [1]

  2. 2

    The End of Queue pointer moves to point to location 9 [1]

  3. 3

    Orange is stored in the location referenced by the End of Queue pointer [1]

  4. 4

    The End of Queue pointer moves to point to location 0 [1]

  5. 5

    Yellow is stored in location 0 (a fifth point: the question is capped at 4 marks)

4. Linked list

A linked list is made of nodes. Each node holds a data item and a pointer to the next node. A start pointer points to the first node. The last node holds a null pointer: there are no further nodes in the list.

To add a node in order, check for a free node and search for the insertion point. Use the first node on the free list, which holds the unused nodes. Change the pointer of the node before to point to the new node. Set the pointer of the new node to point to the node after. Move the free list pointer on to the next free node.

Data is added and removed by changing pointers, not by moving data. A new list has a null start pointer and every node on the free list.

Examiner insight

“The operation of the free list was rarely mentioned (MP1, MP3 and MP6)” “The explanation of how to find the correct insertion point (MP2), where given, was often limited to checking that the value was ‘greater than the previous node’, without taking account of the value in the next node in the list.”

Worked example 14 marks

A linked list holds the data values A, C, D and E in alphabetical order, followed by a null pointer.

Explain how a node containing data value B is added to the list in alphabetic sequence.

  1. 1

    Check for a free node [1]

  2. 2

    Search for the correct insertion point, between A and C [1]

  3. 3

    Assign data value B to the first node in the free list [1]

  4. 4

    The pointer from A is changed to point to the node containing B instead of C [1]

  5. 5

    The pointer from B is changed to point to the node containing C (a fifth point: the question is capped at 4 marks)

  6. 6

    The start pointer of the free list moves to the next free node (a sixth point, also beyond the cap)

5. Stacks and queues in arrays

A stack or queue is implemented with a 1D array and integer variables. The variables hold index numbers of the array, never the data items.

For a stack, declare a 1D array with one element for each stack item and an integer stack pointer. Use the stack pointer as an index to the array, and initialise it to show an empty stack. Push and pop must first check for a full or an empty stack. In a stack that grows upwards, a pop reads the value at TopOfStack, then decrements TopOfStack.

For a queue, declare the array, an integer front pointer and an integer end pointer. Initialise them to represent an empty queue. A count of the items in the queue can also be kept.

Examiner insight

“A very common misunderstanding was what values would be used for the two pointers. These were frequently incorrectly shown as two of the data values (for example, D1 and D2) rather that the array index values (correctly as 5 and 1).” “Only the stronger candidates showed the two pointers as an array index number. All too frequently the pointers were incorrectly labelled with two data items.”

Worked example 15 marks

A programmer decides to implement a queue Abstract Data Type (ADT) in order to store characters received from the keyboard. The queue will need to store at least 10 characters and will be implemented using an array.

Describe the declaration and initialisation of the variables and data structures used to implement the queue.

  1. 1

    Declare a 1D array of size 10 or more [1]

  2. 2

    ...of data type CHAR [1]

  3. 3

    Declare an integer variable for the FrontOfQueuePointer [1]

  4. 4

    Declare an integer variable for the EndOfQueuePointer [1]

  5. 5

    Initialise both pointers to represent an empty queue [1]

6. Linked lists in arrays

A linked list is implemented with two 1D arrays and two variables. One array stores the data. The second stores the pointers: each element holds the index of the next node. The two integer variables hold the index of the first node of the list and of the free list.

The null pointer is a value outside the array indices, such as 0 or −1. Another design is one array of a record type, each record holding a data element and a pointer.

To insert a node, take the first node of the free list, store the data in it, set its pointer to the node after, move the free list pointer on, then change the pointer of the node before.

Examiner insight

“Many answers failed to refer to arrays and variables, even though this was asked for in the question.” “A number of zero-mark answer were seen along with the use of non-linked list terminology e.g. head and tail pointers.”

Worked example 14 marks

A linked list holds the data items D40, D32, D11 and D100, followed by a null pointer. Ptr1 is the start pointer. Ptr2 is the free list pointer. The free list holds F1, F2, F3 and F4, followed by a null pointer.

A new node D6 is inserted between nodes D32 and D11. The algorithm is expressed in four steps. Complete the steps.

```1. Assign the data item ... to ...

  1. Set the ... of this node to point to ...
  2. Set Ptr2 to point to ...
  3. Set pointer of ... to point to ...```
  1. 1

    Assign the data item D6 to F1 [1]

  2. 2

    Set the pointer of this node to point to D11 [1]

  3. 3

    Set Ptr2 to point to F2 [1]

  4. 4

    Set pointer of D32 to point to D6 [1]

Recap

  • An ADT is a collection of data and a set of operations on those data.
  • Stack: push and pop at one end. TopOfStack points to the last value added. A popped value stays in memory but is bypassed.
  • Queue: first in, first out. Add at the end, remove from the front. A circular queue wraps round and never moves items.
  • Linked list: nodes of data and pointer, a start pointer, a null pointer at the end and a free list of unused nodes.
  • Add to or remove from a linked list by changing pointers.
  • In arrays, pointers are index numbers. A linked list needs a data array, a pointer array and two variables.
  • Check before every push, pop, enqueue and dequeue.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. State what is meant by an abstract data type.2 marks
    Answer
    1. A collection of data [1].
    2. And a set of operations on those data [1].

    Trap: Naming one structure, such as a stack, or an array, instead of giving the definition.

  2. Name the ADT that is most suitable for each situation and justify each choice. (a) Print jobs are sent to a printer and must be printed in the order they arrive. (b) A text editor undoes the most recent change first.4 marks
    Answer
    1. (a)
    2. Queue [1]. The first job to join is the next to leave (first in, first out) [1].
    3. (b)
    4. Stack [1]. The last change pushed is the first one popped [1].

    Trap: Giving a reason such as ‘it is faster’ instead of the first-in, first-out or last-in, first-out behaviour that suits the situation.

  3. An empty stack has the following operations performed on it: ```PUSH 'R' PUSH 'E' POP PUSH 'D' PUSH 'O' POP POP``` State the value at the top of the stack and the number of items on the stack.2 marks
    Answer
    1. After the first POP, 'E' is removed. The second POP removes 'O' and the third removes 'D'.
    2. The stack holds only 'R'. The top is 'R' [1] and there is 1 item [1].

    Trap: Removing the oldest item, as a queue would, instead of the most recently pushed item.

  4. A stack uses memory locations 300 to 309. TopOfStack points to the last value added and currently holds 305. State the number of consecutive PUSH operations before the stack is full, and the number of consecutive POP operations before it is empty.2 marks
    Answer
    1. PUSH to 306, 307, 308 and 309: 4 pushes [1].
    2. Values are in 300 to 305, which is 6 values: 6 pops [1].

    Trap: Off by one: 309 - 305 = 4 is right for pushes, but 305 - 300 = 5 misses the value in location 300.

  5. A linked list holds the names Ali, Cai and Eve in that order. (a) State what the pointer in the node for Eve holds. (b) Describe how the node for Cai is deleted.3 marks
    Answer
    1. (a)
    2. A null pointer [1].
    3. (b)
    4. The pointer of the node for Ali is changed to point to the node for Eve [1].
    5. No data is moved. The node for Cai can be returned to the free list [1].

    Trap: Shifting Eve along to fill the gap, as with an array, instead of changing the pointer of the node before.

  6. A circular queue has locations 0 to 5. The Front of Queue Pointer holds 4 and the End of Queue Pointer, which points to the last item added, holds 1. (a) State the number of items in the queue. (b) Item X is added, then item Y is added, then one item is removed. State the new values of the two pointers and the number of items.4 marks
    Answer
    1. (a)
    2. The items are in locations 4, 5, 0 and 1: 4 items [1].
    3. (b)
    4. Adding X moves the End pointer to 2 and adding Y moves it to 3. The End pointer is 3 [1].
    5. Removing moves the Front pointer to 5 [1].
    6. The queue now holds 5 items [1].

    Trap: Working out 1 - 4 and forgetting that the locations wrap round from 5 to 0.

  7. A stack is stored in a 1D array of 8 elements, filled from element 1 upwards. The variables BottomOfStack and TopOfStack hold array indices. The values 'P', 'Q', 'R' and 'S' are pushed in that order onto an empty stack. State the value of each variable.2 marks
    Answer
    1. BottomOfStack = 1 [1].
    2. TopOfStack = 4 [1].

    Trap: Writing 'P' and 'S', the data values, instead of the indices 1 and 4.

  8. A stack of up to 20 values is stored in the 1D array ThisStack[1:20]. The integer SP holds the index of the last value pushed. An empty stack has SP = 0. (a) State the value of SP when the stack is full. (b) Seven values are pushed and then three are popped. State the value of SP. (c) State what ThisStack[7] holds after this.3 marks
    Answer
    1. (a)
    2. SP = 20 [1].
    3. (b)
    4. 7 - 3 = 4 [1].
    5. (c)
    6. It still holds the seventh value pushed, but SP bypasses it [1].

    Trap: Believing that a POP erases the value, or counting a full stack as SP = 21.

  9. A linked list of fruit is stored in two arrays. The variable Start_Pointer holds 3 and Free_List_Pointer holds 5. A pointer of 0 is the null pointer. (a) List the fruit in order. (b) The fruit banana is inserted so that the list stays in alphabetical order. Describe the changes made to the arrays and variables. | Index | Data | Pointer | | --- | --- | --- | | 1 | grape | 0 | | 2 | | 6 | | 3 | apple | 4 | | 4 | cherry | 1 | | 5 | | 2 | | 6 | | 7 | | 7 | | 8 | | 8 | | 0 |5 marks
    Answer
    1. (a)
    2. In order from Start_Pointer 3: apple, cherry, grape [1].
    3. (b)
    4. The new node banana is stored at index 5, the first node of the free list [1].
    5. Free_List_Pointer becomes 2, the pointer in index 5 [1].
    6. The pointer of banana is set to 4, the index of cherry [1].
    7. The pointer of apple (index 3) is changed from 4 to 5 [1].

    Trap: Writing the data value or the wrong index as a pointer, or forgetting to move Free_List_Pointer on.

  10. A warehouse robot uses a stack and a circular queue, each stored in a 1D array. The stack is stored in Stack[1:6]. TopOfStack holds the index of the last value added. The queue is stored in Queue[0:3] and can hold 4 items. FrontPointer holds the index of the next item to be removed. EndPointer holds the index of the last item added. The current state is: TopOfStack = 4, FrontPointer = 3, EndPointer = 0. The table shows both arrays. The following operations are performed: ```1. POP a value and add it to the queue 2. POP a value and add it to the queue 3. Remove one item from the queue and PUSH it``` (a) State the final value of TopOfStack, FrontPointer and EndPointer. (b) State the final contents of every element of both arrays. (c) State the number of items in the queue. | Index | Stack | Queue | | --- | --- | --- | | 0 | | C | | 1 | K | X | | 2 | M | Y | | 3 | R | A | | 4 | W | | | 5 | | | | 6 | | |6 marks
    Answer
    1. The queue starts with 2 items: A (index 3), then C (index 0). X and Y are not in the queue.
    2. Step 1: POP W, TopOfStack = 3. EndPointer moves to 1 and Queue[1] = W.
    3. Step 2: POP R, TopOfStack = 2. EndPointer = 2 and Queue[2] = R. The queue is now full.
    4. Step 3: remove A from Queue[3]. FrontPointer wraps round to 0. PUSH A: TopOfStack = 3 and Stack[3] = A.
    5. (a)
    6. TopOfStack = 3 [1], FrontPointer = 0 [1], EndPointer = 2 [1].
    7. (b)
    8. Stack[1:4] holds K, M, A, W. W is still in Stack[4] but is bypassed [1].
    9. Queue[0:3] holds C, W, R, A. A is still in Queue[3] but is bypassed [1].
    10. (c)
    11. 3 items: C, W, R [1].

    Trap: Giving a pointer as a data value (TopOfStack = A) instead of an array index, or erasing a value that has been popped or removed.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
‘Pointer’ for the end of a linked listnull pointer: there are no further nodes in the list
‘Start’ or ‘start node’start pointer
Push and pop applied to a queueenqueue and dequeue
TopOfStack is D1 (the pointer shown as a data value)The pointer holds an array index, such as 5

Frequently asked questions

What is an abstract data type?
An abstract data type (ADT) is a collection of data and a set of operations on those data. A stack, a queue and a linked list are all ADTs. An ADT says what is stored and what can be done to it. How it is built, for example with arrays, is a separate question.
What is the difference between a stack and a queue?
A stack adds and removes items at the same end: PUSH adds an item and POP removes one, so the last item pushed is the first popped. A queue works on a first in, first out basis: data is added at the end and removed from the front, using enqueue and dequeue. Applying push and pop to a queue shows confusion between ADTs.
How does a linked list insert a node in alphabetic sequence?
First check for a free node, then search for the correct insertion point. Take the first node on the free list, store the data in it, and change the pointer of the node before so it points to the new node. Set the new node's pointer to the node after it. Data is not moved; only pointers change.
How do you implement a stack using an array?
Declare a 1D array with one element for each stack item, and an integer stack pointer. The pointer holds an index into the array, never a data item, and it is initialised to show an empty stack. Push and pop must first check for a full or an empty stack.
What happens to a value when it is popped from a stack?
A POP does not erase the value. It stays in memory, but the TopOfStack pointer bypasses it. A PUSH moves the pointer to the new item, and a POP moves it back to the item below. Popping an empty stack causes an error.
What mistake do students make when a circular queue reaches the end of the array?
They suggest that the existing queue contents must be moved or removed before new data can be added. In a circular queue the End pointer wraps round to location 0, and items already in the queue never move. Check that the queue is not full before adding an item.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters