## Queues

Question 1 |

A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efﬁciently. Which one of the following statements is

**CORRECT**(n refers to the number of items in the queue)?Both operations can be performed in O(1) time | |

At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n) | |

The worst case time complexity for both operations will be Ω(n) | |

Worst case time complexity for both operations will be Ω(logn) |

Question 1 Explanation:

Since it is mentioned in the question that both of the operations are performed efficiently. Hence even the worst case time complexity will be O(1) by the use of the Circular queue there won't be any need of shifting in the array.

Question 2 |

Suppose a circular queue of capacity (n - 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect

*queue full*and*queue empty*arefull: (REAR+1)mod n == FRONT empty: REAR == FRONT | |

full: (REAR+1)mod n == FRONT empty: (FRONT+1) mod n == REAR | |

full: REAR == FRONT empty: (REAR+1) mod n == FRONT | |

full: (FRONT+1)mod n == REAR empty: REAR == FRONT |

Question 2 Explanation:

To circulate within the queue we have to write mod n for (Rear + 1).

We insert elements using Rear & delete through Front.

Question 3 |

Leaves the queue Q unchanged | |

Reverses the order of the elements in the queue Q | |

Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order | |

Empties the queue Q |

Question 3 Explanation:

As a recursive call, and removing from front while inserting from end, that means that element will be deleted at last and will be inserted 1

^{st}in the new queue. And like that it will continue till first call execute insert (Q, i) function. So the queue is in reverse order.
There are 3 questions to complete.