Question 3

OCR Computer Science November 2020 Paper 2AS15 marks

On the specification

(a)(i)
1.4 Data types, data structures and algorithms2.3 Algorithms
(a)(ii)
2.2 Problem solving and programming
(a)(iii)
2.2 Problem solving and programming2.3 Algorithms
(a)(iv)
2.2 Problem solving and programming
(b)(i)
2.3 Algorithms
(b)(ii)
2.3 Algorithms
(b)(iii)
2.3 Algorithms
(b)(iv)
2.3 Algorithms
Question text

3 Oscar owns a taxi company. He would like a program to handle taxi bookings from customers. (a) When a customer makes a booking, they are placed into a queue data structure until a taxi driver is available. (i) Explain why Oscar uses a queue data structure rather than a stack data structure. [4] (ii) Oscar has written a procedure, enqueue, to be able to add a customer number to the queue. The queue is not circular. 1 procedure enqueue(custNumber) 2 maxElements = 10 3 if (tail + 1) > maxElements then 4 print ("Error, queue is full") 5 else 6 head = head + 1 7 queue[head] = custNumber 8 endif 9 endprocedure State the name of the parameter used in the procedure enqueue. [1] (iii) The procedure enqueue contains an error on line 06 and line 07. Rewrite lines 06 and 07 of the procedure enqueue so that the queue works correctly. [2] (iv) Identify the logical condition in the procedure enqueue that affects whether a new Item can be added to the queue. [1] (b) Some of Oscar’s customers are rated as gold. Customers who are rated as gold are given priority when they make a taxi booking. Some customers rated as gold are shown here. Arshad Betty Dave Freddie Harry Jimmy Kanwal Lynn Siad Tommy Will When a customer makes a booking, Oscar will make use of a binary search to check if they are gold rated. Oscar would like to know if ‘Tommy’ is gold rated. (i) State the three values that will be set as the midpoints and then checked against ‘Tommy’ on each iteration of the binary search. Show your working here. Midpoint 1 Midpoint 2 Midpoint 3 [3] (ii) Oscar has 75 000 customers stored in his program. Describe the benefit to Oscar of using binary searches in his program. Benefit [2] (iii) State one other search algorithm that Oscar could have used. [1] (iv) State the pre-condition which has been met which meant that Oscar did not need to use the search algorithm you stated in question 3(b)(iii). [1]