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. Sequence, selection and iteration

OCR A Level Computer Science

Topic questions Programming fundamentals Sequence, selection and iteration

Sequence, selection and iteration

15 questions · 375 marks · about 6.5 hours

Sequence, selection and iteration questions

OCR H446 Sequence, selection and iteration 15 questions

Algorithms and programming June 2025, Question 1 22 marks

Data in a computer program needs to be sorted.

(a)
(a)(i)

Describe the steps a bubble sort will take to sort items into ascending order.

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

Darcie and Felix have both written a program that will perform a bubble sort to put these numbers into ascending order.

Figure for question 1

Darcie’s version will complete six passes. However, Felix’s version will only need to complete two passes.

Explain how Felix may have made his version more efficient than Darcie’s version.

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

A second type of sorting algorithm is an insertion sort.

Describe how an insertion sort can be used to put the following data into ascending order.

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

A third type of sorting algorithm is a quick sort.

The following quick sort algorithm is made up of two functions called partition() and quickSort(). The algorithm will sort an integer array into ascending numerical order.

Figure for question 1
(c)(i)

Identify which of the two functions is recursive and give all of the line numbers where recursive calls are made.

Recursive function name........

Recursive call line numbers........

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

Identify the type of iteration used in the function partition().

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

Describe the role of the function partition() in the quick sort algorithm.

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

The algorithm needs to be changed to sort the integer array into descending numerical order.

Identify the line number that needs to be changed and write the amended line of code.

Amended line of code........

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

The quick sort is an example of a divide-and-conquer algorithm.

Describe what divide-and-conquer means.

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

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 2024, Question 1 9 marks

Also involves Variables, constants, inputs, outputs and assignment

A student has written this pseudocode algorithm:

Figure for question 1
(a)

The program uses variables.

(a)(i)

Describe what is meant by a variable.

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

Give the identifiers of all the variables used in this program.

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

The student has used a do loop on line 02.

Describe the difference between a do loop and a while loop.

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

Rewrite lines 05 to 07 to use a while loop instead of a for loop.

You should write your answer using either program code or pseudocode.

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

Algorithms and programming June 2024, Question 9 40 marks

Also involves Arrays

A game is being written that makes use of object-oriented programming. A prototype for one part of the game is being designed that includes a character, a road and a prize to collect.

The road will have 50 spaces that a character can move along. Each space on the road will store a null value or a prize object for the user to collect. Each space is numbered sequentially from the first space (position 0) to the last space (position 49) and will not change during the game. As the player travels down the road, the position the player is on the road will be output.

(a)

The road is designed to be a 1-dimensional array with the identifier road.

Explain why an array is a suitable data structure to represent the road.

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

The characters and prizes are designed as separate classes. 10 of the spaces on the road will contain an instance of the class Prize. The other spaces will be empty.

The class design for Prize is here.

Figure for question 9

new() is the constructor method. The name, type and value are passed to the constructor as parameters which then assigns these to the attributes.

(b)(i)

The method getName() returns the data in the attribute name.

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

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

A global 1-dimensional array, allPrizes, stores 10 objects of type Prize.

The prize in index 3 has the name "Box", the type is "money" and the value is 25.

Write pseudocode or program code to create a new object for this prize and store it in index 3 of allPrizes.

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

The game starts with 10 prizes. Each prize is allocated to one space on the road.

An algorithm needs designing that will generate a random space on the road for each prize. Each road space can only store one prize.

Describe the decisions that will need to be made in this algorithm and how these will affect the program flow.

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

The class design for Character is here.

Figure for question 9

The four get methods return the associated attribute.

The number of moves is passed to changePosition() as a parameter. The method adds this value to the character’s position on the road.

The type and value of an object are passed to updateValues() as parameters. If the object is money the value is added to the character’s money. If the type is experience the value is added to experience. If the type is neither money or experience no changes are made.

(c)(i)

new() is the constructor method. The name of the character is passed into the constructor as a parameter. The constructor then initialises both the experience and road position of the character to 0 and initialises the amount of money to 5.

Write the constructor method for Character using either pseudocode or program code. You do not need to declare the class, the attributes or any other methods.

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

The type and value of a prize are passed as parameters to the method updateValues. If the type is money the value is added to the character’s money. If the type is experience then the value is added to the experience. If the type is neither money or experience no changes are made.

For example, for the Character player1:

player1.updateValues("money",10) updates player1’s money by 10

player1.updateValues("experience",5) updates player1’s experience by 5

player1.updateValues("foo",9) has no effect on player1.

Write pseudocode or program code for the method updateValues().

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

This incomplete pseudocode algorithm:

• creates a new character with the name Jamal

• loops until the character reaches the end of the road

• generates a random number of spaces to move between 1 and 4 (including 1 and 4)

• moves the character and checks if the new space has a prize

• updates the character attributes if there is a prize

• outputs the character’s new attribute values.

Complete the pseudocode algorithm.

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

The procedure displayRoad() outputs the contents of each space in the road. The number of each space is output with either:

• the word "empty" if there is no prize

• the name of the prize if there is a prize.

Figure for question 9

The algorithm contains errors.

Give the line number of four different errors and write the corrected line for each error.

Error 1

Error 2

Error 3

Error 4

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

* A programmer is going to create a prototype for one small part of the game. Both road and allPrizes will be needed throughout the whole prototype. The programmer is considering making these global arrays as she thinks it will reduce the development time. Another programmer has suggested that doing this may create some problems when the rest of the game is created at a later stage.

Compare the use of global and local variables in this program.

You should include the following in your answer:

• the use of local and global variables

• alternative methods to using global variables

• the appropriateness of each to this program design.

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

Algorithms and programming June 2023, Question 4 8 marks

Also involves Variables, constants, inputs, outputs and assignment · String manipulation

A programmer has designed a program that includes a reusable program component.

(a)

The reusable program component is a function called isInteger(). This will take a string as an argument and then check that each digit is between 0 and 9. For example if 103 is input, it will check that the digits 1, 0 and 3 are each between 0 and 9.

The asc() function returns the ASCII value of each digit. For example asc("1") returns 49.

The ASCII value for 0 is 48. The ASCII value for 9 is 57.

Figure for question 4
(a)(i)

Identify one identifier used in the function isInteger().

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

Give the line number where the branching (selection) construct starts in the function isInteger().

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

Give the line number where the iteration construct starts in the function isInteger()

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

Describe the purpose of the following lines in the function isInteger().

Line 03........

Line 04........

Line 09........

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

Give two reasons why reusable program components are used in programs.

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

Algorithms and programming June 2023, Question 9 40 marks

Also involves Arrays

A text-based computer game allows a user to dig for treasure on an island. The island is designed as a grid with 10 rows and 20 columns to store the treasure. Each square is given an x and y coordinate. Some of the squares in the grid store the name of a treasure object. Each treasure object has a value, e.g. 100 and a level, e.g. "Bronze."

(a)

The computer game makes use of abstraction.

(a)(i)

Describe what is meant by the term abstraction and give an example of how abstraction can be used in the treasure game.

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

Give three benefits of using abstraction when writing a program.

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

The treasure game is being programmed using an object-oriented paradigm.

A class, Treasure, is used to store the treasure objects.

The design for the Treasure class, its attributes and methods is shown here.

Figure for question 9
(b)(i)

The constructor method takes a value as an integer, e.g. 100, and a level, e.g. "bronze", as parameters and assigns these to the attributes.

Write pseudocode or program code to declare the class Treasure.

You should define the attributes and constructor method in your answer.

You do not need to write the get methods.

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

The get method getLevel() will return the appropriate attribute.

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

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

Describe the object-oriented programming technique being used in part 9(b)(ii).

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

A class, Board, is used to store the 10 row (x coordinate) by 20 column (y coordinate) grid.

The design for the Board class, its attributes and methods is shown here.

Figure for question 9

The constructor initialises each space in the grid to a treasure object with value as-1 and level as an empty string.

Complete the following pseudocode for the constructor method.

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

A procedure, guessGrid():

• takes a Board object as a parameter

• accepts the row (x) and column (y) coordinates from the user

• outputs "No treasure" if there is no treasure found at the coordinate (level is an empty string)

• if there is treasure at that coordinate, it outputs the level and the value of the treasure in an appropriate message.

Write the procedure guessGrid() using either pseudocode or program code.

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

Describe two benefits of using an object-oriented paradigm rather than a procedural paradigm.

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

* The main program initialises a new instance of Board. The programmer is considering declaring this as a global variable or as a local variable and then passing this into the subroutines that control the game.

Compare the use of variables and parameters in this game.

You should include the following in your answer:

• what is meant by a local variable and global variable

• how local and global variables can be used in this program

• the use of passing parameters by value and by reference.

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

Algorithms and programming June 2022, Question 1 21 marks

Also involves Variables, constants, inputs, outputs and assignment

A computer program stores data in an array named words.

(a)

The data in the array needs to be searched for a value that the user inputs.

(a)(i)

One example of a searching algorithm is a binary search.

Identify the precondition for a binary search.

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

A second example of a searching algorithm is a linear search.

Describe how a linear search works.

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

The array words is defined as a global variable and contains these values:

Figure for question 1

The pseudocode function useWords() here uses the global array words.

The number of words in the array words is passed as a parameter.

Figure for question 1
(b)(i)

Identify two variables in the function useWords().

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

numberOfWords is a parameter passed by value.

Describe the difference between passing a parameter by value and by reference.

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

Rewrite the function useWords() to use a while loop instead of a for loop.

The function header and close have been written for you.

Write your answer using pseudocode or program code.

function useWords(numberOfWords: byVal)

endfunction

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

Give one benefit and one drawback of declaring the array as a global variable instead of a local variable.

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

Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program.

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

Functions and procedures are reusable components.

Give two benefits of writing a program with reusable components.

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

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 2 14 marks

The pseudocode function binarySearch() performs a binary search on the array dataArray that is passed as a parameter. The function returns the array index of searchValue within the array, and-1 if it is not in the array.

(a)

The pseudocode binary search algorithm is incomplete.

(a)(i)

Complete the algorithm by filling in the missing statements.

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

The algorithm uses a while loop.

State a different type of loop that could be used instead of the while loop in the given algorithm.

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

The tables below show possible Big O complexities for the worst-case space, best-case space and average time for search algorithms.

Tick the worst-case space complexity for a binary and linear search.

Figure for question 2

Tick the best-case space complexity for a binary and linear search.

Figure for question 2

Tick the average time complexity for a binary and linear search.

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

Identify one situation where a linear search is more appropriate than a binary search.

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

Algorithms and programming November 2021, Question 8 40 marks

Also involves Syntax and logic errors · Arrays

Figure for question 8
(a)

Juan is creating a structure diagram to design the game.

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

A structure diagram is one method of showing the decomposition of a problem.

Explain why decomposing a problem can help a developer design a solution.

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

Identify one input, one process and one output required for the game.

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

Juan uses the structure diagram to create a modular program with a number of subroutines. The program will use two integer 2-dimensional arrays to store the puzzles:

• puzzle(5,5) stores the solution

• answerGrid(5,5) stores the user’s current grid.

A 0 represents a white box and a 1 represents a black box.

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

Explain the purpose of line 03 in the function countRow.

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

Describe the purpose of branching and iteration in the function countRow.

[3]
Reveal mark scheme Mark scheme for question 8(b)(iii)
(b)(iv)
Figure for question 8
[6]
Reveal mark scheme Mark scheme for question 8(b)(iv)
(b)(v)

The function checkWon() takes answerGrid and puzzle as parameters and compares each element in the grids. If they are identical, it returns true, otherwise returns false.

Figure for question 8

There are three logic errors in the function checkWon.

State the line number of each error and give 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 8(b)(v)
(c)

* Juan passed the two arrays as parameters, but he did consider making them globally accessible.

Compare the use of global and local variables and data structures in this program. Include the use of parameters and program efficiency in your answer.

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

Juan wants to create a program that will generate new Nonograms with different grid sizes. For example a Nonogram with a 10 × 10 grid or a 5 × 20 grid.

Describe how the program could be written to automatically generate a new Nonogram.

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

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 June 2019, Question 3 17 marks

Also involves Arithmetic operators

A recursive function, GCD, is given in pseudocode.

Figure for question 3
(a)

The function uses branching.

(a)(i)

Identify the type of branching statement used in the function.

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

Explain the difference between branching and iteration.

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

Identify the two parameters in the function.

1

2.

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

State whether the parameters should be passed by value, or by reference. Justify your answer.

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

Describe the arithmetic operation of MOD. Use an example in your answer.

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

Trace the recursive function when it is called by the statement GCD(250, 20). Give the final value returned.

Final return value:.

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

The function has been rewritten using iteration instead of recursion.

(c)(i)

State one benefit and one drawback of using iteration instead of recursion.

Benefit.

Drawback.

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

Complete the missing statements in this iterative version of the function.

Figure for question 3
[4]
Reveal mark scheme Mark scheme for question 3(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)

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