Computer-Science-A-level-Ocr
-
3-3-networks8 主题
-
3-2-databases7 主题
-
3-1-compression-encryption-and-hashing4 主题
-
2-5-object-oriented-languages7 主题
-
2-4-types-of-programming-language4 主题
-
2-3-software-development5 主题
-
2-2-applications-generation6 主题
-
2-1-systems-software8 主题
-
1-3-input-output-and-storage2 主题
-
1-2-types-of-processor3 主题
-
1-1-structure-and-function-of-the-processor1 主题
-
structuring-your-responses3 主题
-
the-exam-papers2 主题
-
8-2-algorithms-for-the-main-data-structures4 主题
-
8-1-algorithms10 主题
-
7-2-computational-methods11 主题
-
7-1-programming-techniques14 主题
-
capturing-selecting-managing-and-exchanging-data
-
entity-relationship-diagrams
-
data-normalisation
-
relational-databases
-
hashing
-
symmetric-vs-asymmetric-encryption
-
run-length-encoding-and-dictionary-coding
-
lossy-and-lossless-compression
-
polymorphism-oop
-
encapsulation-oop
-
inheritance-oop
-
attributes-oop
-
methods-oop
-
objects-oop
-
capturing-selecting-managing-and-exchanging-data
-
6-5-thinking-concurrently2 主题
-
6-4-thinking-logically2 主题
-
6-3-thinking-procedurally3 主题
-
6-2-thinking-ahead1 主题
-
6-1-thinking-abstractly3 主题
-
5-2-moral-and-ethical-issues9 主题
-
5-1-computing-related-legislation4 主题
-
4-3-boolean-algebra5 主题
-
4-2-data-structures10 主题
-
4-1-data-types9 主题
-
3-4-web-technologies16 主题
-
environmental-effects
-
automated-decision-making
-
computers-in-the-workforce
-
layout-colour-paradigms-and-character-sets
-
piracy-and-offensive-communications
-
analysing-personal-information
-
monitoring-behaviour
-
censorship-and-the-internet
-
artificial-intelligence
-
the-regulation-of-investigatory-powers-act-2000
-
the-copyright-design-and-patents-act-1988
-
the-computer-misuse-act-1990
-
the-data-protection-act-1998
-
adder-circuits
-
flip-flop-circuits
-
simplifying-boolean-algebra
-
environmental-effects
linked-lists
Linked Lists
What is a linked list?
-
In A Level Computer Science, a linked list is a dynamic data structure that is used to hold an ordered sequence
-
The items which form the sequence do not have to be in contiguous data locations
-
Each item is called a node and contains a data field alongside another address which is called a pointer
-
For example:
|
Index |
Data |
Pointer |
|---|---|---|
|
0 |
‘Apple’ |
2 |
|
1 |
‘Pineapple’ |
0 |
|
2 |
‘Melon’ |
– |
|
3 |
|
|
Start = 1 NextFree = 3
-
The data field contains the value of the actual data which is part of the list
-
The pointer field contains the address of the next item in the list
-
Linked lists also store the index of the first item as a pointer
-
They also store a pointer identifying the index of the next available space
Examiner Tips and Tricks
-
Linked lists can only be traversed by following each item’s next pointer until the end of the list is located
Linked Lists: Traversing, Adding & Removing Data
Traverse a linked list
-
Check if the linked list is empty
-
Start at the node the pointer is pointing to (Start = 1)
-
Output the item at the current node (‘Pineapple’)
-
Follow the pointer to the next node repeating through each node until the end of the linked list.
-
When the pointer field is empty/null it signals that the end of the linked list has been reached
-
Traversing the example above would produce: ‘Pineapple’, ‘Apple’, ‘Melon’
Adding a node
-
An advantage of using linked lists is that values can easily be added or removed by editing the points
-
The following example will add the word ‘Orange’ after the word ‘Pineapple’
1. Check there is free memory to insert data into the node
2. Add the new value to the end of the linked list and update the ‘NextFree’ pointer
|
3 |
‘Orange’ |
|
Start = 1 NextFree = 4
3. The pointer field of the word ‘Pineapple’ is updated to point to ‘Orange’, at position 3
|
1 |
‘Pineapple’ |
3 |
4. The pointer field of the word ‘Orange’ is updated to point to ‘Apple’ at position 0
|
3 |
‘Orange’ |
0 |
4. When traversed this linked list will now output: ‘Pineapple’, ‘Orange’, ‘Apple’, ‘Melon’
Removing a node
-
Removing a node also involves updating nodes, this time to bypass the deleted node
-
The following example will remove the word ‘Apple’ from the original linked list
1. Update the pointer field of ‘Pineapple’ to point to ‘Melon’ at index 2
|
Index |
Data |
Pointer |
|---|---|---|
|
0 |
‘Apple’ |
2 |
|
1 |
‘Pineapple’ |
2 |
|
2 |
‘Melon’ |
– |
2. When traversed this linked list will now output: ‘Pineapple’, ‘Melon’
-
The node is not truly removed from the list; it is only ignored
-
Although this is easier it does waste memory
-
Storing pointers themselves also means that more memory is required compared to an array
-
Items in a linked list are also stored in a sequence, they can only be traversed within that order so an item cannot be directly accessed as is possible in an array
Worked Example
A coach company offers tours of the UK
A linked list stores the names of cities on a coach tour in the order they are visited.

linked-lists-question
The tour is amended. The new itinerary is London, Oxford, Manchester then York. Explain how Birmingham is removed from the linked list and how York is added. You may use the diagram to illustrate your answer.
4 marks
Answer:
Example answer that gets full marks:
The first thing you need to do is change the Oxford pointer to go around Birmingham to point to Manchester. [1]

linked lists WE 1
Then you create a node called York and this is placed at the next free space in the list. [1]

linked lists WE 2
Manchester is kept in the same position and it’s pointer changed to point to York. [1]

linked lists WE 3
The York node then points to Null. [1]
Responses