Question 2
OCR Computer Science Specimen Paper 2AS7 marks
On the specification
- (a)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (b)
- 2.2 Problem solving and programming1.4 Data types, data structures and algorithms
- (c)(i)
- 2.3 Algorithms1.4 Data types, data structures and algorithms
- (c)(ii)
- 2.3 Algorithms1.4 Data types, data structures and algorithms
Question text
2 The array queue shown below is set up to hold a small queue. Assume that there is sufficient storage to hold all necessary additions to the queue. Queue rear front The table below shows variables that are used to maintain the queue: Variable Type Purpose front integer pointer to the front element of the queue rear integer pointer to the rear element of the queue queue_full Boolean indicates whether the queue is full max integer the maximum size of the queue Shown below is an algorithm that is intended to add an item to the queue. procedure add_to_queue (item) if ((front – rear) +1) == max then queue_full=true else front=front + 1 queue[front]=item endif endprocedure (a) Identify the parameter that is passed to this procedure. [1] (b) Describe the logical decision that is made. [2] (c) (i) This algorithm contains a logic mistake. Explain what the mistake is. [2] (ii) Rewrite the algorithm to correct the mistake. [2]