Question 4
OCR Computer Science June 2016 Paper 2AS22 marks
On the specification
- (a)
- 2.3 Algorithms
- (b)
- 2.3 Algorithms2.2 Problem solving and programming
- (c)(i)
- 2.3 Algorithms
- (c)(ii)
- 2.3 Algorithms
- (d)
- 1.4 Data types, data structures and algorithms2.2 Problem solving and programming
Question text
4 (a) Describe the steps involved in a binary search to find the value 47 in the list below. 4, 7, 8, 21, 46, 47, 51 [4] (b) A programmer has been tasked with writing a function that uses a binary search to return a Boolean value. The function should return true if the target integer is found in a list of integers. Using pseudocode, write an algorithm for the function. [8] (c) The target integer 8 exists in a list of integers 1, 4, 6, 9, 8, 12, 15 but is not found during a binary search. There are no errors in the code. (i) Give the reason why the target integer 8 is not found. [1] (ii) Identify and describe an alternative search algorithm that could be used. [3] (d) A stack, in shared memory, is being used to pass a single variable length ASCII string between two sub-systems. The string is placed in the stack one character at a time in reverse order with the last byte holding the number of characters pushed i.e the text “SILVER” would be held in the stack as: 6 Top S I L V E R Use pseudocode to write a procedure that will take a text string passed to it and push it to the stack in the format defined above. You may assume any given input will fit in the stack. [6]