Question: (3) Queues (20 points) We consider different array-based implementations of a queue of integers. (a) (12 points) In all parts of this question, consider the


(3) Queues (20 points) We consider different array-based implementations of a queue of integers. (a) (12 points) In all parts of this question, consider the following array of 6 integers, with the contents of the array as shown, with the starting index of the array being 0 index 0 1 2 3 4 5 Each of following questions (i)-iv) presents an array-based implementation of a queue. For each question, you have to decide whether the implementation is correct. You have to justify your In each implementation, we assume that the front and rear indices were both initialized to 0 at the beginning to indicate an empty queue. After some enqueueing and dequeueing operations we now have the array as shown above. () (4 points) In implementation I, front is now 2, rear is 5, and the integers in the queue (from front to rear) are 5, 1, 2,3. (ii) (4 points) In implementation II, front is now 2, rear is 5, and the integers in the queue (from front to rear) are 5, 1, 2 (iii (4 points) In implementation III, front is now 2, rear is 5, and the integers in the queue (from front to rear) are 1, 2. 3 (iv) (4 points) In implementation IV, front is now 2, rear is 5, and the integers in the queue (from front to rear) are 7, 6, 3 (b) (4 points) Consider the same array of 6 integers in (a), with the contents of the array as shown: index 0 1 2 3 4 5 6 7 5 2 3 Assume that the starting index of the array is O. Now, this array is being used as a priority queue, where the entries are maintained in ascending order from front to rear. We assume that the front and rear indices were both initialized to 0 at the beginning. After some enqueueing and dequeueing operations, we now have the array as shown above, where the priority queue is full and has the following valid entries (from front to rear): 1,2, 3,6,7 Now, you want to enqueue 4 into the priority queue. The enqueue operation involves the following steps: (1) Double the size of the array to accommodate the growth; (2) Make the fewest number of data moves to turn the expanded array into a valid queue; and (3) Insert 4 into the priornty queue. Show the contents of the priority queue after each of the three steps. For entries whose content are not known, use" for those entries. After step (D
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
