BREAKING
Student's code works, nobody knows why, including studentβ˜…Local teen writes pseudocode, accidentally invents a languageβ˜…Binary joke told in class, exactly 10 students laughβ˜…
  1. Home
  2. A Level
  3. Computer Science
  4. OCR
  5. Algorithms for the main data structures

OCR A Level Computer Science

Topic questions Algorithms Algorithms for the main data structures

Algorithms for the main data structures

22 questions · 496 marks · about 9 hours

Algorithms for the main data structures questions

OCR H446 Algorithms for the main data structures 22 questions

Algorithms and programming June 2025, Question 3 17 marks

A program is designed to use a stack data structure.

The current contents of part of the stack and its current pointer value are shown:

Figure for question 3

pointer = 2

(a)

Show the contents of the stack and its pointer value after the data items "t" and "s" are inserted in the order given.

Figure for question 3
[2]
Reveal mark scheme Mark scheme for question 3(a)
(b)

The stack is stored using a 0-based 1-dimensional array called theStack with 20 elements.

The function push() stores its parameter into the next space in the stack if it is not full. The function returns true if it is successfully stored and returns false if the stack is full.

Complete the function push() using pseudocode or program code.

Figure for question 3
[4]
Reveal mark scheme Mark scheme for question 3(b)
(c)

A pointer value of-1 indicates that the stack is empty.

The function pop() returns the next element in the stack. If the stack is empty it returns "false". The function updates the pointer value when appropriate.

Write the function pop() using pseudocode or program code.

[6]
Reveal mark scheme Mark scheme for question 3(c)
(d)

A program is designed to reverse a set of data using the stack.

The main program takes 10 characters separately as input from the user and uses the function push() to insert these into the stack.

Once all 10 characters have been inserted into the stack, the program then uses the function pop() to output all 10 characters from the stack.

Write the main program to achieve this using pseudocode or program code.

[5]
Reveal mark scheme Mark scheme for question 3(d)

Algorithms and programming June 2025, Question 7 9 marks

An ordered binary search tree contains the following data:

Figure for question 7
(a)

Add the following data items in the given order to the binary search tree above. 5 30 53 57 90

[3]
Reveal mark scheme Mark scheme for question 7(a)
(b)

A balanced binary search tree has data consistently at each level, for example:

Figure for question 7

An unbalanced binary search tree is uneven, for example:

Figure for question 7

Describe the drawback of an unbalanced binary search tree when searching for a value.

[2]
Reveal mark scheme Mark scheme for question 7(b)
(c)

A different binary search tree stores the following data:

Figure for question 7

Give the output that will be produced from a depth-first (post-order) traversal and a breadth-first traversal of this binary search tree.

Depth-first (post-order)........

[4]
Reveal mark scheme Mark scheme for question 7(c)

Algorithms and programming June 2025, Question 8 40 marks

Also involves Arrays Β· Linked lists

A linked list data structure is designed using object-oriented programming.

The design includes two classes called node and linkedList.

(a)

Describe the features of a linked list data structure.

[3]
Reveal mark scheme Mark scheme for question 8(a)
(b)

The class design for node is shown here.

Figure for question 8

new() is the constructor method. The constructor method takes a parameter and assigns this to the value attribute.

(b)(i)

The method getNextNode() returns the attribute nextNode.

Write the method getNextNode() using pseudocode or program code.

[2]
Reveal mark scheme Mark scheme for question 8(b)(i)
(b)(ii)

The method setValue() takes an integer as a parameter and assigns this to the attribute value

Write the method setValue() using pseudocode or program code.

[3]
Reveal mark scheme Mark scheme for question 8(b)(ii)
(c)

The class design for linkedList is shown here.

Figure for question 8

new() is the constructor method. The constructor initialises the attribute headNode to a null value.

(c)(i)

Write the constructor method using pseudocode or program code.

[2]
Reveal mark scheme Mark scheme for question 8(c)(i)
(c)(ii)

The class design for node and linkedList are shown again here for your reference.

Figure for question 8

The method getValue() will return the value of a node. The method getNextNode() will return the next node to be accessed in the linked list.

The method outputList() traverses the linked list starting at the node headNode. The method joins the data in each node and returns it.

Complete the method outputList() using pseudocode or program code.

Figure for question 8
[5]
Reveal mark scheme Mark scheme for question 8(c)(ii)
(d)

The method insertNode() will insert a new node into the linked list.

The method accepts an integer as a parameter, creates a new node with that data and inserts it into the linked list, e.g. insertNode(8) creates a node object with the data 8 and adds it to the linked list.

The program needs to store the following data items in the linked list in the order they are given: 10 25 39

The program then needs to output all of the data in the list using the appropriate method.

Write an algorithm using pseudocode or program code to:

β€’ create a new linkedList object with the identifier createList

β€’ insert each of the data items into the linked list (10, 25, 39)

β€’ output the content of the linked list.

[5]
Reveal mark scheme Mark scheme for question 8(d)
(e)

A new method is needed to remove a node from the linked list. The method needs to take the data to remove as a parameter and then find this data in the linked list before removing the node.

Describe the steps that this method will need to follow and the decisions that need to be made in the method to remove the correct node.

[5]
Reveal mark scheme Mark scheme for question 8(e)
(f)

The program developer made use of computational methods when designing the object-oriented programming solution. One computational method is divide-and-conquer.

Identify three other computational methods that the program developer could have used.

[3]
Reveal mark scheme Mark scheme for question 8(f)
(g)

* This program uses classes and objects to create a linked list.

An alternative method is creating a 2-dimensional array. In this design the first index stores the data and the second element stores the index of the next data item. Array elements not currently used are also linked together to form a chain of empty values to identify where the next data item can be inserted.

Compare the two different methods of creating a linked list that have been described.

You should include the following in your answer:

β€’ the features of both methods including the reusability of program components

β€’ benefits and drawbacks of both methods in this program

β€’ a conclusion evaluating the efficiency of both methods when designing a program that needs

a linked list.

[12]
Reveal mark scheme Mark scheme for question 8(g)

Algorithms and programming June 2024, Question 4 6 marks

Also involves Stacks and queues

Figure for question 4
(a)

State the purpose of headPointer and tailPointer in the queue shown in Fig. 4.

[2]
Reveal mark scheme Mark scheme for question 4(a)
(b)
Figure for question 4
[2]
Reveal mark scheme Mark scheme for question 4(b)
(c)

The queue is used to store ID numbers of jobs that a program needs to process. Some jobs will be given a priority which means they need to be processed first.

Explain why this queue is not a suitable data structure for this program.

[2]
Reveal mark scheme Mark scheme for question 4(c)

Algorithms and programming June 2024, Question 5 12 marks

Also involves Arrays

The contents of a stack are stored in the 1-dimensional array called numbers.

topStack stores the index of the next free space in the stack.

The array is declared with space for 100 elements.

(a)

The function pop() returns the next item from the stack and updates the appropriate pointers.

Describe the steps in the function pop().

[4]
Reveal mark scheme Mark scheme for question 5(a)
(b)

The function push() inserts its parameter called dataValue onto the stack and updates the appropriate pointers.

Complete the function push() using pseudocode or program code.

Figure for question 5
[4]
Reveal mark scheme Mark scheme for question 5(b)
(c)

Write an algorithm, using pseudocode or program code, to call the function push() with the value 15 and output a message saying "Added" if the value was successfully inserted onto the stack or "Not Added" if the stack is full.

[4]
Reveal mark scheme Mark scheme for question 5(c)

Algorithms and programming June 2024, Question 7 13 marks

Also involves Records Β· Trees and binary search trees

A computer game stores tasks that the player has requested. Each task has:

β€’ an identification (ID) number e.g. Task A

β€’ a real number to be processed e.g. 123456.789

β€’ an integer number to represent the order the tasks should be accessed e.g. 1.

The task that needs to be processed the earliest is given the order number 1.

Two or more tasks can have the same order number. For example, two tasks can have an order number 1.

(a)

The data about each task needs to be stored. This will store the ID number, data value and order number for a task.

Explain why a record data structure is suitable for this data.

[2]
Reveal mark scheme Mark scheme for question 7(a)
(b)

The tasks will be stored in a binary search tree before they are processed. They are stored in ascending order by their order number.

(b)(i)

Give two characteristics of a binary search tree.

[2]
Reveal mark scheme Mark scheme for question 7(b)(i)
(b)(ii)

Give an advantage of storing the tasks in a binary search tree instead of a 1-dimensional array.

[1]
Reveal mark scheme Mark scheme for question 7(b)(ii)
(b)(iii)
Figure for question 7
[5]
Reveal mark scheme Mark scheme for question 7(b)(iii)
(b)(iv)

The tasks currently stored in the binary search tree are shown here.

When a new task is inserted with the same order number as a pre-existing task, it is classed as having a higher order number.

For example, task G has the same order number as task A. Since task G was inserted after task A it is classed as a higher number.

Change the diagram to show the contents of the binary search tree after the following tasks are inserted in the order given:

β€’ Task X with order number 12

β€’ Task Y with order number 7

β€’ Task Z with order number 11

Figure for question 7
[3]
Reveal mark scheme Mark scheme for question 7(b)(iv)

Algorithms and programming June 2023, Question 1 24 marks

A tree is one example of a data structure.

(a)(i)

Give two characteristics of a tree data structure.

[2]
Reveal mark scheme Mark scheme for question 1(a)(i)
(a)(ii)

The following data is entered into a binary search tree.

22 13 5 36 55 14 8

Draw the binary search tree when the given data is entered in the order given.

[4]
Reveal mark scheme Mark scheme for question 1(a)(ii)
(a)(iii)

Describe how a leaf node is deleted from a binary search tree.

[2]
Reveal mark scheme Mark scheme for question 1(a)(iii)
(a)(iv)

Describe how a binary search tree can be searched for a value.

[4]
Reveal mark scheme Mark scheme for question 1(a)(iv)
(a)(v)

Identify the order that the nodes will be visited in a depth-first (post-order) traversal of this binary search tree.

Figure for question 1
[4]
Reveal mark scheme Mark scheme for question 1(a)(v)
(a)(vi)

Explain how backtracking is used in depth-first (post-order) traversals.

[2]
Reveal mark scheme Mark scheme for question 1(a)(vi)
(b)
Figure for question 1 Figure for question 1 Figure for question 1
[6]
Reveal mark scheme Mark scheme for question 1(b)

Algorithms and programming June 2023, Question 3 14 marks

Also involves Linked lists

A program stores data in a linked list.

The current contents of the linked list are shown in Fig. 3, along with the linked list pointers.

Figure for question 3
(a)

State the purpose of headPointer and freeListPointer in the linked list shown in Fig. 3.

[2]
Reveal mark scheme Mark scheme for question 3(a)
(b)

State the meaning of the pointers with the value NULL in the linked list shown in Fig. 3.

[1]
Reveal mark scheme Mark scheme for question 3(b)
(c)

A procedure outputs the data in the linked list shown in Fig. 3 from the first item in the list, to the last item.

Give the output from the procedure.

[2]
Reveal mark scheme Mark scheme for question 3(c)
(d)

A new item needs to be added to the linked list.

Describe how a new item is added to a linked list.

[4]
Reveal mark scheme Mark scheme for question 3(d)
(e)

The function findNode will search the linked list and return either the position of the node that contains the data item, or-1 if the data item is not found.

The data held in a node at location x can be accessed with linkedList[x].data. The pointer of the node at location x can be accessed with linkedList[x].pointer.

Figure for question 3

Complete the function, using pseudocode or program code.

Figure for question 3
[5]
Reveal mark scheme Mark scheme for question 3(e)

Algorithms and programming June 2022, Question 2 16 marks

Also involves Trees and binary search trees

A computer program is being written to store data about students.

Fig. 2 shows a binary search tree that stores data about students.

Each student is represented by their ID number. The current contents of the binary search tree are:

Question 2, shown as an image

Fig. 2

(a)

Identify the root node in the binary tree shown in Fig. 2.

[1]
Reveal mark scheme Mark scheme for question 2(a)
(b)

Identify two leaf nodes in the binary tree shown in Fig. 2.

[2]
Reveal mark scheme Mark scheme for question 2(b)
(c)

Four more students are added to the binary search tree shown in Fig. 2 in this order:

1420 2050 2780 2600

Complete the binary search tree here by adding the new students to it.

Question 2, shown as an image
[4]
Reveal mark scheme Mark scheme for question 2(c)
(d)

* A programmer would like to traverse the binary search tree shown in Fig. 2.

Compare the use of a breadth-first traversal and a depth-first (post-order) traversal on the binary search tree.

You should include the following in your answer:

β€’ how each traversal works

β€’ the order of the return values for each traversal.

[9]
Reveal mark scheme Mark scheme for question 2(d)

Algorithms and programming June 2022, Question 8 40 marks

Also involves Programming paradigms

A computer uses a stack data structure, implemented using an array, to store numbers entered by the user.

The array is zero based and has 100 locations.

(a)
Figure for question 8
(a)(i)
Figure for question 8
[2]
Reveal mark scheme Mark scheme for question 8(a)(i)
(a)(ii)

State the purpose of pointerValue.

[1]
Reveal mark scheme Mark scheme for question 8(a)(ii)
(b)

The stack is programmed as an object using object-oriented programming. The design for the class, its attributes and methods are shown:

Figure for question 8
(b)(i)

The method pop() returns the next value in the stack, or –1 if the stack is empty.

Complete the pseudocode method pop().

Figure for question 8
[5]
Reveal mark scheme Mark scheme for question 8(b)(i)
(b)(ii)

The method push() accepts an integer as a parameter and adds it to the top of the stack unless the stack is already full.

If the push is successful the method returns true.

If the push is unsuccessful due to the stack being full the method returns false.

Write the method push() using either pseudocode or program code.

[6]
Reveal mark scheme Mark scheme for question 8(b)(ii)
(b)(iii)

The main program initialises a new object of type stack with the identifier mathsStack

Write pseudocode or program code to declare the object.

[2]
Reveal mark scheme Mark scheme for question 8(b)(iii)
(b)(iv)

The main program needs to:

β€’ take numbers as input from the user

β€’ push them onto the stack mathsStack until the stack is full

β€’ output an appropriate message if the stack is full.

Complete the pseudocode algorithm to meet these requirements.

Figure for question 8
[4]
Reveal mark scheme Mark scheme for question 8(b)(iv)
(b)(v)

The main program also needs to:

β€’ remove one item from the stack at a time and add this to a total

β€’ output the total every time an item is removed

β€’ stop removing items when either the stack is empty, or 20 items have been removed.

Write pseudocode or program code to meet these requirements.

[8]
Reveal mark scheme Mark scheme for question 8(b)(v)
(c)

The program is amended to include the use of several queue data structures.

(c)(i)

Describe how an array can be used to implement a queue data structure.

[3]
Reveal mark scheme Mark scheme for question 8(c)(i)
(c)(ii)

* Discuss the use of object-oriented programming and procedural programming to create and manipulate the queue data structures.

You should include the following in your answer:

β€’ the features of object-oriented programming

β€’ the features of procedural programming

β€’ the benefits of using object-oriented instead of procedural programming when creating several queue structures.

[9]
Reveal mark scheme Mark scheme for question 8(c)(ii)

Algorithms and programming November 2021, Question 1 33 marks

Taylor is creating an online multiplayer game where users can create accounts and build their own circus. Each circus will contain characters such as clowns, animals, magicians and dancers.

Users can set up a new circus in the online world, purchase new characters and visit other users’ circuses.

(a)

Taylor uses computational methods to analyse the problem including abstraction.

Describe how Taylor could use abstraction in the design of his online circus game.

[3]
Reveal mark scheme Mark scheme for question 1(a)
(b)

Taylor will make use of concurrent processing within his circus game.

(b)(i)

Describe what is meant by the term β€˜concurrent processing’.

[2]
Reveal mark scheme Mark scheme for question 1(b)(i)
(b)(ii)

Explain why concurrent processing is needed to allow multiple users to log in and interact with game elements at the same time.

[3]
Reveal mark scheme Mark scheme for question 1(b)(ii)
(c)

Some of the characters in the game will move and interact independently. Taylor is going to use graphs to plan the movements that each character can take within the game.

DancerGold is one character. The graph shown in Fig. 1 shows the possible movements that DancerGold can make.

Figure for question 1

DancerGold’s starting state is represented by node A. DancerGold can take any of the paths to reach the end state represented by node G.

The number on each path represents the number of seconds each movement takes.

The number in bold below each node is the heuristic value from A.

(c)(i)

Define the term heuristic in relation to the A* algorithm.

[2]
Reveal mark scheme Mark scheme for question 1(c)(i)
(c)(ii)

Perform an A* algorithm on the graph shown in Fig. 1 to find the shortest path from the starting node to the end node. Show your working, the nodes visited and the distance. You may choose to use the table below to give your answer.

Figure for question 1
[8]
Reveal mark scheme Mark scheme for question 1(c)(ii)
(d)

A breadth-first traversal can be performed on both a tree and a graph.

Show how a breadth-first traversal is performed on the following binary tree.

Figure for question 1
[6]
Reveal mark scheme Mark scheme for question 1(d)
(e)

* The game will have thousands of users. Taylor will store data about the users and their actions while playing the game in a large database.

Evaluate how Taylor can use data mining to inform future changes to improve his circus game.

[9]
Reveal mark scheme Mark scheme for question 1(e)

Algorithms and programming November 2021, Question 7 9 marks

Lucas writes a program that makes use of a circular queue. The queue stores the data entered into the program. An array is used to represent the queue.

(a)

The program needs two pointers to access and manipulate the data in the queue.

State the purpose of the two pointers and give an appropriate identifier for each.

Pointer 1 purpose........

Pointer 1 identifier........

Pointer 2 purpose........

Pointer 2 identifier........

[4]
Reveal mark scheme Mark scheme for question 7(a)
(b)

Lucas wants a procedure, enqueue(), that will add the parameter it is passed to the queue.

Describe the steps the procedure enqueue() will follow when adding new items to the queue.

[5]
Reveal mark scheme Mark scheme for question 7(b)

Algorithms and programming November 2020, Question 1 19 marks

Also involves Trees and binary search trees Β· Graphs (data structure)

Kira is creating a computer game where the user can play against the computer.

In each turn, each character can make one move from a selection of possible moves.

Kira uses a tree data structure shown in Fig. 1 to identify the range of possible moves the computer can make from starting position A. Each connection is a move, with each node representing the result of the move.

Figure for question 1
(a)

State what is meant by the term β€˜abstraction’ and describe how Kira has used abstraction in her design of the tree.

[3]
Reveal mark scheme Mark scheme for question 1(a)
(b)

State why the tree shown in Fig. 1 is not an example of a binary search tree.

[1]
Reveal mark scheme Mark scheme for question 1(b)
(c)

State what type of pointers are used to store nodes I, F, J and H so they do not point to any other nodes.

[1]
Reveal mark scheme Mark scheme for question 1(c)
(d)

Kira wants the program to traverse the tree to evaluate the range of possible moves. She is considering using a breadth-first traversal or a depth-first (post-order) traversal.

Show how a breadth-first traversal would traverse the tree shown in Fig. 1.

[4]
Reveal mark scheme Mark scheme for question 1(d)
(e)

Kira wants to make some changes to the data that is stored in the tree structure shown in Fig. 1.

(e)(i)

The move represented by node β€˜E’ needs to be deleted.

Describe the steps an algorithm will follow to delete node β€˜E’ from the tree.

[3]
Reveal mark scheme Mark scheme for question 1(e)(i)
(e)(ii)

The move represented by the node β€˜K’ needs to be added. Node β€˜K’ needs to be joined to node β€˜G.’

Describe the steps the algorithm will follow to add node β€˜K’ to the right of node β€˜G’.

[3]
Reveal mark scheme Mark scheme for question 1(e)(ii)
(f)

Kira could have used a graph data structure to represent the moves in her game.

Give two similarities and two differences between a tree and a graph data structure.

[4]
Reveal mark scheme Mark scheme for question 1(f)

Algorithms and programming November 2020, Question 5 32 marks

Also involves Arrays Β· Stacks and queues

A printer buffer is a storage area that holds the data, known as jobs, that are to be printed by a printer.

A simulation of the printer buffer uses a queue data structure to store jobs that are waiting to be printed. The queue is not circular.

The printer buffer is represented as a zero-indexed 1D array with the identifier buffer.

Fig. 2 shows the current contents of the queue buffer and its pointers.

Figure for question 5
(a)

State the purpose of the pointers queueHead and queueTail.

[2]
Reveal mark scheme Mark scheme for question 5(a)
(b)
Figure for question 5
[5]
Reveal mark scheme Mark scheme for question 5(b)
(c)

The array, buffer and pointer values are declared with global scope.

(c)(i)

The function dequeue returns null if the array is empty, and the contents of the next element if not empty. The queue is not circular.

Write an algorithm, using pseudocode or program code, for the function dequeue()

[5]
Reveal mark scheme Mark scheme for question 5(c)(i)
(c)(ii)

The function enqueue returns-1 if there is no space at the end of the queue to add data, and returns 1 if the parameter was added to buffer. The array buffer contains a maximum of 100 elements.

Write an algorithm, using pseudocode or program code, for the function enqueue()

[6]
Reveal mark scheme Mark scheme for question 5(c)(ii)
(c)(iii)

In the main program of the simulation the user is asked whether they want to add an item to the queue or remove an item.

If they choose to add an item they have to input the job name, and the function enqueue is called.

If they choose to remove an item, the function dequeue is called and the job name is output.

Appropriate messages are output if either action cannot be run because the queue is either empty or full.

Write, using pseudocode or program code, an algorithm for the main program of the simulation.

[8]
Reveal mark scheme Mark scheme for question 5(c)(iii)
(d)

The queue is changed to make it a circular queue.

Describe how the functions enqueue and dequeue will need to be changed to allow buffer to work as a circular queue.

[3]
Reveal mark scheme Mark scheme for question 5(d)
(e)

Some print jobs can have different priorities. The higher the priority the sooner the job needs to be printed.

Describe how the program could be changed to deal with different priorities.

[3]
Reveal mark scheme Mark scheme for question 5(e)

Algorithms and programming November 2020, Question 6 40 marks

Barney is writing a program to store data in a linked list. He is writing the initial program for a maximum of 10 data items.

Each node in the linked list has a data value and a pointer (to the next item).

A null pointer is stored with the value –1.

(a)
Figure for question 6
(a)(i)

Describe the purpose of freeListPointer.

[2]
Reveal mark scheme Mark scheme for question 6(a)(i)
(a)(ii)

State the purpose of headPointer.

[1]
Reveal mark scheme Mark scheme for question 6(a)(ii)
(a)(iii)
Figure for question 6
[4]
Reveal mark scheme Mark scheme for question 6(a)(iii)
(b)

Barney wants the nodes to be stored as objects using object-oriented programming. He designs the following class.

Figure for question 6

The constructor assigns the parameters to the attributes to create an object.

(b)(i)
Figure for question 6
[4]
Reveal mark scheme Mark scheme for question 6(b)(i)
(b)(ii)

The class node, uses get methods and set methods.

Describe one difference between get methods and set methods.

[2]
Reveal mark scheme Mark scheme for question 6(b)(ii)
(c)

The function findNodePath() takes the data item to find in the linked list as a parameter and follows the pointers to find the required node.

The function returns the array indexes of all the nodes it visits and joins this to a suitable message stating whether the data was found or not found and then returns this as one string.

Describe how the function findNodePath() will search for the data item and return the required message.

[6]
Reveal mark scheme Mark scheme for question 6(c)
(d)

The procedure printLinkedList() follows the pointers to print all of the elements in the linked list.

Figure for question 6

The procedure has a number of errors.

(d)(i)

Identify the line of each error and write the corrected line.

Error 1 line number........

Error 1 correction........

Error 2 line number........

Error 2 correction........

Error 3 line number........

Error 3 correction........

[3]
Reveal mark scheme Mark scheme for question 6(d)(i)
(d)(ii)

Barney will use an Integrated Development Environment (IDE) to debug his program code.

Describe three features commonly found in IDEs that Barney could use to debug his program code.

[6]
Reveal mark scheme Mark scheme for question 6(d)(ii)
(e)

* Barney would like his linked list to be part of a base program that is saved in a library. This means that it can be reused and changed by other programs.

Discuss the benefits of using different object-oriented techniques that Barney could use to achieve this.

[12]
Reveal mark scheme Mark scheme for question 6(e)

Algorithms and programming June 2019, Question 2 22 marks

Also involves Trees and binary search trees

A program needs to store the names of plants that are in a garden, so they can be easily found and accessed in alphabetical order.

The data is stored in a tree structure. Part of the tree is shown.

Figure for question 2
(a)
(a)(i)

State the type of tree shown in Fig. 2.1.

[1]
Reveal mark scheme Mark scheme for question 2(a)(i)
(a)(ii)

Show the output of a breadth-first traversal of the tree shown in Fig. 2.1.

[3]
Reveal mark scheme Mark scheme for question 2(a)(ii)
(a)(iii)

Explain how backtracking is used in a depth-first (post-order) traversal. Use the tree in Fig. 2.1 in your explanation.

Figure for question 2
[4]
Reveal mark scheme Mark scheme for question 2(a)(iii)
(b)

The elements in the tree in Fig. 2.1 are read into a linked list producing an alphabetised list.

(b)(i)

Complete the following table to show the linked list for the data.

Figure for question 2
[2]
Reveal mark scheme Mark scheme for question 2(b)(i)
(b)(ii)

A new plant, Lavender, needs adding to the linked list. The linked list needs to retain its alphabetical order.

Complete the table to show the linked list after Lavender is added.

Figure for question 2
[3]
Reveal mark scheme Mark scheme for question 2(b)(ii)
(b)(iii)

Hosta needs removing from the linked list.

Explain how a data item is removed from a linked list. Use the removal of Hosta in your answer.

[4]
Reveal mark scheme Mark scheme for question 2(b)(iii)
(b)(iv)

The linked list is stored as a 2D array with the identifier plantList. The index of the first element of the linked list is stored in the identifier firstElement.

All contents of the linked list need to be output in alphabetical order.

Write an algorithm to follow the pointers to output the contents of the linked list in alphabetical order.

Add comments to explain your code.

[5]
Reveal mark scheme Mark scheme for question 2(b)(iv)

Algorithms and programming June 2018, Question 1 13 marks

A program stores entered data in a binary search tree.

The current contents of the tree are shown:

Figure for question 1
(a)

Complete the diagram to show the contents of the tree after the following data is added:

England, Scotland, Wales, Australia

[3]
Reveal mark scheme Mark scheme for question 1(a)
(b)

Show the order of the nodes visited in a breadth first traversal on the following tree.

Figure for question 1
[3]
Reveal mark scheme Mark scheme for question 1(b)
(c)

A pseudocode algorithm is written to search the tree to determine if the data item β€œSweden” is in the tree.

The function currentNode.left()returns the node positioned to the left of currentNode

Figure for question 1
(c)(i)

Complete the algorithm.

[5]
Reveal mark scheme Mark scheme for question 1(c)(i)
(c)(ii)

The algorithm needs to be used in different scenarios, with a range of different trees.

Identify two preconditions needed of a tree for this algorithm to work.

[2]
Reveal mark scheme Mark scheme for question 1(c)(ii)

Algorithms and programming June 2018, Question 5 29 marks

Also involves String manipulation

A computer program stores data input on a stack named dataItems. The stack has two sub-programs to add and remove data items from the stack. The stack is implemented as a 1D array, dataArray.

Figure for question 5

The current contents of dataItems are shown:

Figure for question 5
(a)
Figure for question 5
[4]
Reveal mark scheme Mark scheme for question 5(a)
(b)

The main program asks a user to push or pop an item from the stack. If the user chooses β€˜push’, the data item is added to the stack. If the user chooses β€œpop”, the next item is removed from the stack, multiplied by 3 and output.

The main program is shown:

Figure for question 5
(b)(i)

Before the sub-programs, push() and pop(), can add or remove items from the stack, a selection statement is used to decide if each action is possible.

Describe the decision that needs to be made in each sub-program and how this impacts the next process.

Question 5, shown as an image
Question 5, shown as an image
[4]
Reveal mark scheme Mark scheme for question 5(b)(i)
(b)(ii)

The algorithm does not work when the user enters "PUSH" or "Push". The algorithm needs to be changed in order to accept these inputs.

Identify the line number to be changed and state the change that should be made.

Question 5, shown as an image
[2]
Reveal mark scheme Mark scheme for question 5(b)(ii)
(c)

The stack is implemented as a 1D array, dataArray.

Describe how a 1D array can be set up and used to push and pop items as a stack.

Figure for question 5

maths symbol

[3]
Reveal mark scheme Mark scheme for question 5(c)
(d)

As an array, the data in dataArray is sorted and then searched for a specific value.

(d)(i)

The data in dataArray is sorted into ascending order using an insertion sort.

The current contents of dataArray are shown:

Figure for question 5

Show the steps of an insertion sort on the current contents of the array dataArray.

Figure for question 5

maths symbol

[5]
Reveal mark scheme Mark scheme for question 5(d)(i)
(d)(ii)

The array dataArray can now be searched using a binary search.

Describe the stages of a binary search on an array of size n.

Figure for question 5

maths symbol

[7]
Reveal mark scheme Mark scheme for question 5(d)(ii)
(d)(iii)

The array has 50 items.

The function, searchItem(), performs a linear search for a data item.

Figure for question 5

Rewrite the function using a while loop.

Figure for question 5

maths symbol

[4]
Reveal mark scheme Mark scheme for question 5(d)(iii)

Algorithms and programming June 2018, Question 6 40 marks

Also involves File handling Β· Records Β· Stacks and queues

Kamran is writing a program to manipulate the data for a set of items.

For each item, the program needs to store:

β€’ Item name (e.g. Box)

β€’ Cost (e.g. 22.58)

β€’ Date of arrival (e.g. 1/5/2018)

β€’ Transferred (e.g. true)

The items are added to a queue for processing.

The queue is defined as a class, itemQueue.

Figure for question 6

The head attribute points to the first element in the queue. The tail attribute points to the next available space in the queue. The numItems attribute states how many items are currently in the queue.

(a)

The data about the items can be stored using either a record structure, or as objects of a class.

(a)(i)

Explain the similarities and differences between a record and a class.

Figure for question 6

maths symbol

[3]
Reveal mark scheme Mark scheme for question 6(a)(i)
(a)(ii)

Kamran chooses to use a record structure to store the data about the items.

Record structures may be declared using the following syntax:

Figure for question 6

Complete the pseudocode to declare a record called items.

Figure for question 6
[5]
Reveal mark scheme Mark scheme for question 6(a)(ii)
(a)(iii)

New records may be created using the following syntax:

Figure for question 6

Write a programming statement to create a new item, using the identifier β€˜box1’, with the item name β€œBox”, the cost 22.58, date of arrival 1/5/2018 and transferred true.

Figure for question 6

maths symbol

[3]
Reveal mark scheme Mark scheme for question 6(a)(iii)
(b)

The array, theItems, stores the items in the queue. When the tail of the queue exceeds the last element in the array, it adds a new item to the first element if it is vacant.

For example, in the following queue, the next item to be added would be placed at index 0.

Index0123456789
ElementDataDataDataDataDataDataData
(b)(i)

Define the term β€˜queue’.

Figure for question 6

maths symbol

[2]
Reveal mark scheme Mark scheme for question 6(b)(i)
(b)(ii)

The attributes in itemQueue are all declared as private.

Explain how a private attribute improves the integrity of the data.

Figure for question 6

maths symbol

[2]
Reveal mark scheme Mark scheme for question 6(b)(ii)
(b)(iii)

The constructor method creates a new instance of itemQueue and sets the head, tail and numItems attributes to 0.

Write an algorithm, using pseudocode or program code, for the constructor including the initialisation for all attributes.

Figure for question 6

maths symbol

[2]
Reveal mark scheme Mark scheme for question 6(b)(iii)
(b)(iv)

The enqueue method:

maths symbol takes as a parameter the item to insert in the queue

maths symbol checks if the queue is full

maths symbol reports an error and returns false if the queue is full

maths symbol does the following if the queue is not full: o adds the item to the array at the tail position and adjusts the pointer(s) o returns true

The attribute numItems stores the number of items currently in the queue.

Write an algorithm, using pseudocode or program code, for the enqueue method.

Figure for question 6

maths symbol

[6]
Reveal mark scheme Mark scheme for question 6(b)(iv)
(b)(v)

Write a programming statement to declare an instance of itemQueue called myItems

Figure for question 6
[1]
Reveal mark scheme Mark scheme for question 6(b)(v)
(b)(vi)

Write a procedure, insertItems(), to ask the user to input the data for an item. The item is then added to the queue myItems. The user is continually asked to input data items until the queue is full.

Figure for question 6

maths symbol

[5]
Reveal mark scheme Mark scheme for question 6(b)(vi)
(b)(vii)

When the main program ends, the items and the queue no longer exist.

Describe how Kamran could amend the program to make sure the items and queue still exist and are used the next time the program is run.

Figure for question 6

maths symbol

[2]
Reveal mark scheme Mark scheme for question 6(b)(vii)
(c)

* Kamran wants to expand the program to allow it to handle up to 100,000,000 items and to allow him to search for data about items. Kamran is worried that the increase in the number of items will cause a decrease in the performance of the program. He decides to investigate the benefits of caching and concurrent processing.

Evaluate the use of caching and concurrent processing in this scenario and make a recommendation to Kamran.

Figure for question 6

maths symbol

[9]
Reveal mark scheme Mark scheme for question 6(c)

Algorithms and programming June 2017, Question 2 35 marks

Also involves Trace tables Β· Arrays Β· Linked lists

A programmer is developing an ordering system for a fast food restaurant. When a member of staff inputs an order, it is added to a linked list for completion by the chefs.

(a)

Explain why a linked list is being used for the ordering system.

[2]
Reveal mark scheme Mark scheme for question 2(a)
(b)
Figure for question 2
(b)(i)

Order 158 has been made, and needs adding to the end of the linked list.

Add the order, 158, to the linked list as shown in Fig. 2.1. Show the contents of the linked list in the following table.

Figure for question 2
[2]
Reveal mark scheme Mark scheme for question 2(b)(i)
(b)(ii)

Order 159 has been made. This order has a high priority and needs to be the second order in the linked list. Add the order, 159, to the original linked list as shown in Fig. 2.1. Show the contents of the linked list in the following table.

Figure for question 2
[3]
Reveal mark scheme Mark scheme for question 2(b)(ii)
(c)

The linked list is implemented using a 2D array, theOrders:

β€’ Row 0 stores orderNo

β€’ Row 1 stores next

The data now stored in theOrders is shown in Fig. 2.2.

Figure for question 2

The following algorithm is written:

Figure for question 2
(c)(i)

Outline why nodeNo does not need to be stored in the array.

[1]
Reveal mark scheme Mark scheme for question 2(c)(i)
(c)(ii)

Complete the trace table for procedure x, for the data shown in Fig. 2.2.

Figure for question 2
[3]
Reveal mark scheme Mark scheme for question 2(c)(ii)
(c)(iii)

Describe the purpose of procedure x.

[2]
Reveal mark scheme Mark scheme for question 2(c)(iii)
(c)(iv)

A new order, 190, is to be added to theOrders. It needs to be the third element in the list. The current contents of the array are repeated here for reference:

Figure for question 2

Describe how the new order, 190, can be added to the array, so the linked list is read in the correct order, without rearranging the array elements.

[4]
Reveal mark scheme Mark scheme for question 2(c)(iv)
(d)

The user needs to be able to search for, and find, a specific order number.

State an appropriate search algorithm that could be used, and justify your choice against an alternative Search algorithm.

Appropriate Search Algorithm........

[3]
Reveal mark scheme Mark scheme for question 2(d)
(e)

The programmer is writing the program using an IDE.

Identify three features of an IDE that the programmer would use when writing the code and describe how the features benefit the programmer.

[6]
Reveal mark scheme Mark scheme for question 2(e)
(f)

(f*) The programmer is considering using concurrent programming.

Discuss how concurrent programming can be applied to the food ordering system and the

benefits and limitations of doing so.

[9]
Reveal mark scheme Mark scheme for question 2(f)

Algorithms and programming June 2017, Question 3 19 marks

Also involves String manipulation Β· File handling

An encryption routine reads a line of text from a file, reverses the order of the characters in the string and subtracts 10 from the ASCII value of each letter, then saves the new string into the same file.

The program is split into sub-procedures. Three sub-procedures are described as follows:

β€’ Read string from file

β€’ Push each character of the string onto a stack

β€’ Read and encrypt each character message

(a)(i)

Identify one further sub-procedure that could be used in the program.

[1]
Reveal mark scheme Mark scheme for question 3(a)(i)
(a)(ii)

Describe two advantages of splitting the problem into sub-procedures.

[4]
Reveal mark scheme Mark scheme for question 3(a)(ii)
(b)

A function, readMessage:

β€’ takes the file name as a parameter

β€’ reads and returns the line of text

Complete the pseudocode algorithm for readMessage:

Figure for question 3
[4]
Reveal mark scheme Mark scheme for question 3(b)
(c)

A function, push, can be used to add a character to a stack. For example:

theStack.push("H")

places the character H onto the stack, theStack.

A procedure, pushToStack, takes a string as a parameter and pushes each character of the message onto the stack, messageStack.

Complete the procedure below.

Add comments to explain how your code works.

procedure pushToStack(message)

endprocedure

[5]
Reveal mark scheme Mark scheme for question 3(c)
(d)

Describe the steps that the program would have to take in order to encrypt the characters stored in the stack, and save them in a single variable.

[5]
Reveal mark scheme Mark scheme for question 3(d)

Algorithms and programming June 2017, Question 4 14 marks

Also involves Trees and binary search trees

Figure for question 4
(a)

Identify the data structure shown in Fig. 4.1.

[1]
Reveal mark scheme Mark scheme for question 4(a)
(b)

The programmer is considering using a depth-first (post-order) traversal, or a breadth-first traversal to find the path between node A and node X.

(b)(i)

Explain the difference between a depth-first (post-order) and breadth-first traversal.

[4]
Reveal mark scheme Mark scheme for question 4(b)(i)
(b)(ii)

Show how a depth-first (post-order) traversal would find the path between node A and node X for the structure shown in Fig. 4.1.

[6]
Reveal mark scheme Mark scheme for question 4(b)(ii)
(b)(iii)

Explain how you used backtracking in your answer to part (b)(ii).

[3]
Reveal mark scheme Mark scheme for question 4(b)(iii)

Report a problem with a question on this page
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Memes

Certified Computer Science memes. Peer-reviewed by nobody.

Laugh now. Cry in the exam hall later. Then come back and do a past paper.

Write a proper algorithm
Write β€˜sort it’ and leave
Me on the 6-mark pseudocode question
Debugging with print statements
Using a trace table
Knowing the difference between = and ==
Explaining recursion by explaining recursion
Code enlightenment, ranked

Mum πŸ’–

can you fix the wifi since you do computers πŸ₯°

that's not what computer science is

so that's a no then

πŸ“± Screen time this week Β· Discord8h 2m

Turned it off and on again

Computer Science starter pack

Laptop with 47 tabs openPython error on line 1Counting binary on fingersThis website
Compiled with zero errors