Question 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
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]
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.
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]
The contents of processedData are shown.
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]