Question 1
OCR Computer Science June 2019 Paper 2A level17 marks
On the specification
- (a)
- 1.4 Data types, data structures and algorithms
- (b)(i)
- 2.2 Problem solving and programming
- (b)(ii)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (b)(iii)
- 2.3 Algorithms
- (b)(iv)
- 2.3 Algorithms
Question text
1 The temperatures of an ocean are input into a computer system. They are recorded, and will be accessed, in the order in which they arrive. The data for one week is shown: 5, 5.5, 5, 6, 7, 6.5, 6 (a) The data is to be stored in a data structure. The programmer stores the data in a queue. Explain why a queue is used instead of a stack. [2] (b) The data is processed. After processing, the value for the first day is stored as 0. The value for each following day is stored as an increase, or decrease, from the first day. For example: if the first day was 7, the second was 6 and the third was 9, after processing it would be stored as 0, –1, 2. (i) The queue uses dequeue() to return the first element of the queue. dequeue() is a function. Explain why dequeue() is a function, not a procedure. [1] (ii) Complete the algorithm to process the data in the queue and store the results in an array called processedData. processedData[0] = 0 firstDay = for count = 1 to 6 processedData[ ] = dequeue() – next count [3] (iii) The contents of processedData are shown. 0.5 0 1 2 1.5 1 The data needs to be sorted into ascending order. Explain how a bubble sort algorithm sorts data. Use the current contents of processedData in your explanation. [5] (iv) A bubble sort has the following complexities: Best time O(n) 2 Average and worst time O(n ) Worst space O(1) Describe what each of these complexities mean. Best time O(n) 2 Average and worst time O(n ) Worst Space O(1) [6]