ExamBank Scot · Higher Computing Science question bank · All Higher Computing Science questions

Higher Computing Science 2016 Question 13 (CfE)

8 marks · Testing and debugging

A trace table is shown below which shows the line numbers where a variable has changed. State the missing values at A, B, C and D Line list target counter found 1 [71,76,66,67,89,72] 2 A 3 B 4 0 6 C 4 1 8 D A = B = C = D = The algorithm is incorrect and so outputs the wrong message. Explain why the algorithm is incorrect. Describe how to correct the algorithm. Explain why the use of cache memory improves system performance when running lines 4 to 10. Eloïse wants to search for an item of data held in an array. She writes the following algorithm. Line 1 SET list to [71,76,66,67,89,72] Line 2 SET target to 71 Line 3 SET found to false Line 4 FOR counter FROM 0 to 5 DO Line 5 IF list[counter]=target THEN Line 6 SET found to true Line 7 ELSE Line 8 SET found to false LINE 9 END IF LINE 10 END FOR LINE 11 IF found =true THEN LINE 12 SEND “Item found” TO DISPLAY LINE 13 ELSE LINE 14 SEND “Not found” TO DISPLAY LINE 15 END IF

Marking scheme

A=71 B=false C=true D=false • Resets found to false for every non-matching item. • Continues looping after target found. Any one bullet for 1 mark Remove lines 7 and 8 OR Use a conditional loop until found is true(or end of list) • The code for the loop/array values will be present in cache (1) • meaning faster access than going to slower main memory (1)

Previous question: Higher Computing Science 2016 Question 12 (CfE)

Next question: Higher Computing Science 2016 Question 14 (CfE)