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

Higher Computing Science 2018 Question 7 (CfE)

3 marks · Standard algorithms

Complete lines 8 and 10 below. Line 8 SET Line 10 UNTIL <end of list> OR State the value that would be returned by the function if the target item was not in the list. The incomplete function shown below performs a linear search to find the position of the target item in the following array of strings. Meena Sean Gianni Ali Nyah Lynn When Meena is entered as the target item then 0 is returned. If Lynn is entered as the target item then 5 is returned. Line 1 FUNCTION linearSearch(ARRAY OF STRING list)RETURNS INTEGER Line 2 DECLARE index INITIALLY -1 Line 3 DECLARE position INITIALLY -1 Line 4 DECLARE target AS STRING INITIALLY FROM KEYBOARD Line 5 REPEAT Line 6 SET index TO index+1 Line 7 IF target=list[index] THEN Line 8 SET Line 9 END IF Line 10 UNTIL <end of list> OR Line 11 RETURN position Line 12 END FUNCTION

Marking scheme

Line 8: position to index (1 mark) Line 10: 1 mark for any bullet • target=list(position) • target = list(index) • position = index -1

Previous question: Higher Computing Science 2018 Question 6 (CfE)

Next question: Higher Computing Science 2018 Question 8 (CfE)