A Level Computer Science 9618 Paper 42, May/June 2024

Question paper and mark scheme75 marks3 questions

Solve it on ExamPal

Practise

Untimed. Write on the paper and check as you go.

Start

Exam

Timed, with a clock you set, like sitting the real paper.

Start

Opens full screen.

Papers open in

Opening the question paper

Read as textThe questions and the mark scheme as plain text. Easier to read on a phone.

Question paper

9618/42 · May/June 2024

Download PDF
1

A program outputs a main word. The program asks the user to enter the different words of 3 or more letters that can be made from the letters in the main word. These are called the answers. There are 3 files: Easy.txt, Medium.txt and Hard.txt. Each file has the main word on the first line. For example, the main word in Easy.txt is house. The answers are stored in the file. Each answer is on a new line after the main word. For example, Easy.txt has 14 answers that can be made from the letters in house. The words read from the text file are stored in the global array WordArray. The number of words that can be made from the letters in the main word is stored in the global variable NumberWords.

a

The procedure ReadWords(): • takes a file name as a parameter • opens the file and reads in the data • stores the main word in the first element in WordArray • stores each answer in a new element in WordArray • counts and stores the number of answers. Write program code for the procedure ReadWords(). Save your program as Question1_J24. Copy and paste the program code into part 1(a) in the evidence document.

[6]
b

The main program asks the user to enter "easy", "medium" or "hard" and calls ReadWords() with the filename that matches the user’s input. For example, if the user enters "easy", the parameter is "Easy.txt". Write program code for the main program. Save your program. Copy and paste the program code into part 1(b) in the evidence document.

[4]
c(i)

The procedure Play(): • outputs the main word from the array and the number of answers • allows the user to enter words until they enter the word ‘no’ to indicate they want to stop • outputs whether each word the user enters is an answer or not an answer • counts the number of answers the user gets correct • replaces each answer that the user gets correct with a null value in the array. Write program code for the procedure Play(). Save your program. Copy and paste the program code into part 1(c)(i) in the evidence document.

[6]
c(ii)

Amend the procedure Play() so that when the user enters the command to stop, the procedure: • outputs the percentage of answers the user entered from the array • outputs all the answers that the user did not enter. Write program code to amend Play(). Save your program. Copy and paste the program code into part 1(c)(ii) in the evidence document.

[3]
d(i)

The procedure ReadWords() calls Play() after the data in the file has been read. Write program code to amend ReadWords(). Save your program. Copy and paste the program code into part 1(d)(i) in the evidence document.

[1]
d(ii)

Test your program by inputting these words in the order shown: easy she out no Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(d)(ii) in the evidence document.

[1]
d(iii)

Test your program by inputting these words in the order shown: hard fine fined idea no Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(d)(iii) in the evidence document.

[1]
2

A binary tree stores data in ascending order. For example: 15 8 19 3 10 A computer program stores integers in a binary tree in ascending order. The program uses Object-Oriented Programming (OOP). The binary tree is stored as a 1D array of nodes. Each node contains a left pointer, a data value and a right pointer. The class Node stores the data about a node. Node LeftPointer : INTEGER - stores the index of the node to the left in the binary tree Data : INTEGER - stores the node’s data RightPointer : INTEGER - stores the index of the node to the right in the binary tree Constructor() - initialises Data to its parameter value; initialises LeftPointer and RightPointer to −1 GetLeft() - returns the left pointer GetRight() - returns the right pointer GetData() - returns the data value SetLeft() - assigns the parameter to the left pointer SetRight() - assigns the parameter to the right pointer SetData() - assigns the parameter to the data

Figure 1 of 1 for question 2
a(i)

Write program code to declare the class Node and its constructor. Do not declare the other methods. Use the appropriate constructor for your programming language. If you are writing in Python, include attribute declarations using comments. Save your program as Question2_J24. Copy and paste the program code into part 2(a)(i) in the evidence document.

[4]
a(ii)

The get methods GetLeft(), GetRight() and GetData() each return the relevant attribute. Write program code for the three get methods. Save your program. Copy and paste the program code into part 2(a)(ii) in the evidence document.

[3]
a(iii)

The set methods SetLeft(), SetRight() and SetData() each take a parameter and then store this in the relevant attribute. Write program code for the three set methods. Save your program. Copy and paste the program code into part 2(a)(iii) in the evidence document.

[3]
b(i)

The class TreeClass stores the data about the binary tree. TreeClass Tree[0:19] : Node - an array of 20 elements of type Node FirstNode : INTEGER - stores the index of the first node in the tree NumberNodes : INTEGER - stores the quantity of nodes in the tree Constructor() - initialises FirstNode to −1 and NumberNodes to 0; initialises each element in Tree to a Node object with the data value of −1 InsertNode() - takes a Node object as a parameter, inserts it in the array and updates the pointer for its parent node OutputTree() - outputs the left pointer, data and right pointer of each node in Tree Nodes cannot be deleted from this tree. Write program code to declare the class TreeClass and its constructor. Do not declare the other methods. Use the appropriate constructor for your programming language. If you are writing in Python, include attribute declarations using comments. Save your program. Copy and paste the program code into part 2(b)(i) in the evidence document.

[4]
b(ii)

The method InsertNode() takes a Node object, NewNode, as a parameter and inserts it into the array Tree. InsertNode() first checks if the tree is empty. If the tree is empty, InsertNode(): • stores NewNode in the array Tree at index NumberNodes • increments NumberNodes • stores 0 in FirstNode. If the tree is not empty, InsertNode(): • stores NewNode in the array Tree at index NumberNodes • accesses the data in the array Tree at index FirstNode and compares it to the data in NewNode • repeatedly follows the pointers until the correct position for NewNode is found • once the position is found, InsertNode() sets the left or right pointer of its parent node • increments NumberNodes. Write program code for InsertNode(). Save your program. Copy and paste the program code into part 2(b)(ii) in the evidence document.

[6]
b(iii)

The method OutputTree() outputs the left pointer, the data and the right pointer for each node that has been inserted into the tree. The outputs are in the order they are saved in the array. If there are no nodes in the array, the procedure outputs ‘No nodes’. Write program code for OutputTree(). Save your program. Copy and paste the program code into part 2(b)(iii) in the evidence document.

[4]
c(i)

The main program declares an instance of TreeClass with the identifier TheTree. Write program code for the main program. Save your program. Copy and paste the program code into part 2(c)(i) in the evidence document.

[1]
c(ii)

The main program inserts the following integers into the binary tree in the order given: 10 11 5 1 20 7 15 The main program then calls the method OutputTree(). Write program code to amend the main program. Save your program. Copy and paste the program code into part 2(c)(ii) in the evidence document.

[4]
c(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 2(c)(iii) in the evidence document.

[1]
3

A program sorts an array of integers and searches the array for a particular value.

a

The array of integers, NumberArray, stores the following data in the order given: 100 85 644 22 15 8 1 The array is declared and initialised local to the main program. Write program code to declare and initialise the array. Save your program as Question3_J24. Copy and paste the program code into part 3(a) in the evidence document.

[1]
b(i)

The following recursive pseudocode function sorts the array into ascending order using an insertion sort and returns the sorted array. DECLARE LastItem : INTEGER DECLARE CheckItem : INTEGER DECLARE LoopAgain : BOOLEAN FUNCTION RecursiveInsertion(IntegerArray : ARRAY[] OF INTEGER, NumberElements : INTEGER) RETURNS ARRAY[] OF INTEGER IF NumberElements <= 1 THEN RETURN IntegerArray ELSE CALL RecursiveInsertion(IntegerArray, NumberElements - 1) LastItem ← IntegerArray[NumberElements - 1] CheckItem ← NumberElements - 2 ENDIF LoopAgain ← TRUE IF CheckItem < 0 THEN LoopAgain ← FALSE ELSE IF IntegerArray[CheckItem] < LastItem THEN LoopAgain ← FALSE ENDIF ENDIF WHILE LoopAgain IntegerArray[CheckItem + 1] ← IntegerArray[CheckItem] CheckItem ← CheckItem - 1 IF CheckItem < 0 THEN LoopAgain ← FALSE ELSE IF IntegerArray[CheckItem] < LastItem THEN LoopAgain ← FALSE ENDIF ENDIF ENDWHILE IntegerArray[CheckItem + 1] ← LastItem RETURN IntegerArray ENDFUNCTION Write the program code for the pseudocode function RecursiveInsertion(). Save your program. Copy and paste the program code into part 3(b)(i) in the evidence document.

[4]
b(ii)

Amend the main program to: • call RecursiveInsertion() with the initialised array NumberArray and the number of elements as parameters • output the word ‘Recursive’ • output the content of the returned array. Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document.

[2]
b(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(b)(iii) in the evidence document.

[1]
c(i)

The function RecursiveInsertion() can be changed to use iteration instead of recursion. Write program code for the function IterativeInsertion() to perform the same processes as RecursiveInsertion() but using iteration instead of recursion. Save your program. Copy and paste the program code into part 3(c)(i) in the evidence document.

[4]
c(ii)

Write program code to amend the main program to also: • call IterativeInsertion() with the original initialised array NumberArray • output the word ‘iterative’ • output the content of the returned array. Save your program. Copy and paste the program code into part 3(c)(ii) in the evidence document.

[1]
c(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(c)(iii) in the evidence document.

[1]
d(i)

The recursive function BinarySearch() takes the parameters: • IntegerArray – an array of integers • First – the index of the first array element • Last – the index of the last array element • ToFind – an integer to search for in the array. The function uses recursion to perform a binary search for ToFind in IntegerArray. The function returns the index where ToFind is stored or returns −1 if ToFind is not in the array. Write program code for the recursive function BinarySearch(). Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.

[6]
d(ii)

Write program code to amend the main program to: • call BinarySearch() with the sorted array and the integer 644 as the search value • output ‘Not found’ if 644 is not found in the array • output the index if 644 is found in the array. Save your program. Copy and paste the program code into part 3(d)(ii) in the evidence document.

[2]
d(iii)

Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(d)(iii) in the evidence document.

[1]

Mark scheme

9618/42 · May/June 2024

Download PDF

1a · 6 marks

  • 1 mark

    Procedure declaration (and end where appropriate) taking (string) parameter

  • 1 mark

    Declaration of array to store the data read (type string, suitable number of elements e.g. 150)

  • 1 mark

    Opening file to read…

  • 1 mark

    ... using exception handling with try and catch and output

  • 1 mark

    Reading in the data for each line in that file and storing in array… … removing carriage return (Java, Python)

  • 1 mark

    Counting the number of words / Closing the file (might be within the Python opening file statement)

1b · 4 marks

  • 1 mark

    Outputting message to ask user to enter easy, medium, hard

  • 1 mark

    Taking input from user

  • 1 mark

    Conversion of input to filename…

  • 1 mark

    … calling ReadWords() with correct filename in each case

1c(i) · 6 marks

  • 1 mark

    Procedure (and end) taking array and number of answers as parameters and outputting the main word and the number of answers

  • 1 mark

    Loops until user requests to stop (enters "no") ….

  • 1 mark

    … takes word as input and compares input to each answer in array but not the main word

  • 1 mark

    … method of recording answers found e.g. replaces with "" (or appropriate null)

  • 1 mark

    … outputs if found and not found

  • 1 mark

    Counts the number of answers found (in loop, second array, any method)

1c(ii) · 3 marks

  • 1 mark

    Calculates and outputs percentage of answers found (when ‘no’ is entered)

  • 1 mark

    Method of identifying answers not found (e.g. looping array and skipping null values)…

  • 1 mark

    … and outputting those answers

1d(i) · 1 mark

  • 1 mark

    Calling Play() with array and number of answers after all read in from file

1d(ii) · 1 mark

  • 1 mark

    screenshot showing the inputs "easy", "she", "out", "no"

1d(iii) · 1 mark

  • 1 mark

    screenshot showing the inputs ‘hard’, ‘fine’, ‘fined’, ‘idea’, ‘no’

2a(i) · 4 marks

  • 1 mark

    Class declaration (and end where appropriate) with identifier Node

  • 1 mark

    LeftPointer, Data and RightPointer, integer

  • 1 mark

    Constructor taking 1 parameter (within class) …

  • 1 mark

    … assigning parameter to Data initialising LeftPointer and RightPointer to –1

2a(ii) · 3 marks

  • 1 mark

    1 get method with no parameter…

  • 1 mark

    …returning correct attribute

  • 1 mark

    Remaining 2 correct (FT minor errors)

2a(iii) · 3 marks

  • 1 mark

    1 set method with parameter …

  • 1 mark

    … assigning to attribute

  • 1 mark

    Remaining 2 correct (FT minor errors)

2b(i) · 4 marks

  • 1 mark

    Class header (and end)

  • 1 mark

    Private array Tree of type Node with 20 elements, private FirstNode and private NumberNodes

  • 1 mark

    Constructor assigns –1 to FirstNode and 0 to NumberNodes

  • 1 mark

    … initialises all Tree (20) elements to Node object with data value –1

2b(ii) · 6 marks

  • 1 mark

    Method header and end, taking node as parameter and checking if empty and inserting in first position, updating FirstNode

  • 1 mark

    … otherwise inserting node in tree

  • 1 mark

    Accessing first node and comparing data …

  • 1 mark

    … checking whether to go left or right …

  • 1 mark

    … repeatedly until data found

  • 1 mark

    Updating left and right pointer for parent node

2b(iii) · 4 marks

  • 1 mark

    Procedure header (and end) with no parameter and if no nodes output ‘No nodes’

  • 1 mark

    (otherwise) Loop from index 0 to NumberNodes (or equivalent) …

  • 1 mark

    … Outputting LeftPointer, Data then RightPointer

  • 1 mark

    … using get methods

2c(i) · 1 mark

  • 1 mark

    Instance of TreeClass created with identifier TheTree

2c(ii) · 4 marks

  • 1 mark

    Creating one node with one correct value (e.g. 10)

  • 1 mark

    Calling InsertNode for TheTree with each new Node

  • 1 mark

    All nodes correctly assigned in order

  • 1 mark

    Calling OutputTree

2c(iii) · 1 mark

  • 1 mark

    correct output

3a · 1 mark

  • 1 mark

    NumberArray declared (in main) with the 7 correct values in order (integer) 100 85 644 22 15 8 1

3b(i) · 4 marks

  • 1 mark

    Recursive function written with recursive call

  • 1 mark

    Correct base case and return

  • 1 mark

    Correct while loop control and internal

  • 1 mark

    All correct and structure followed

3b(ii) · 2 marks

  • 1 mark

    Calling RecursiveInsertion() with array and number of elements (7 or length)

  • 1 mark

    Outputting ‘recursive’ and then each element in returned array

3b(iii) · 1 mark

  • 1 mark

    screenshot with: Recursive 1 8 15 22 85 100 644

3c(i) · 4 marks

  • 1 mark

    Insertion algorithm written with correct identifier – no recursion

  • 1 mark

    External loop while there are still elements left (e.g. NumberElements > 0)

  • 1 mark

    Internal loop and selection accurate

  • 1 mark

    Nothing additional added / logic changed

3c(ii) · 1 mark

  • 1 mark

    Calling IterativeInsertion() with original unsorted array and outputting ‘iterative’ and the content of the returned array

3c(iii) · 1 mark

  • 1 mark

    Recursive 1 8 15 22 85 100 644 Iterative 1 8 15 22 85 100 644

3d(i) · 6 marks

  • 1 mark

    Recursive function BinarySearch taking the 4 indicated parameters

  • 1 mark

    Suitable base case (e.g. First > Last) … … returning –1

  • 1 mark

    Calculating middle element

  • 1 mark

    Comparing ToFind with middle and returning Middle if found

  • 1 mark

    If ToFind less than middle, recursive call with Last as Middle – 1

  • 1 mark

    If ToFind more than middle, recursive call with First as Middle + 1

3d(ii) · 2 marks

  • 1 mark

    Calling BinarySearch function with sorted array, 0, 6/len(array)–1, 644 as parameters

  • 1 mark

    Checking return value and outputting ‘Not found’ if –1 and index otherwise

3d(iii) · 1 mark

  • 1 mark

    screenshot showing found in index 6

Questions

  1. 1
    Question 122 marks
    Mark scheme ›
  2. 2
    Question 230 marks
    Mark scheme ›
  3. 3
    Question 323 marks
    Mark scheme ›

More 9618 papers

Other papers from May/June 2024

Solve it on ExamPalStart