GATE Overflow - Recent questions tagged queues
https://gateoverflow.in/tag/queues
Powered by Question2AnswerQueue implementaion using stack
https://gateoverflow.in/158526/queue-implementaion-using-stack
A queue is implemented using 2 stacks. Minimum no. of stack operations (PUSH and POP) required for the sequence of 3 insertions and 2 delete operations in the queue is ------- .DShttps://gateoverflow.in/158526/queue-implementaion-using-stackMon, 09 Oct 2017 06:20:12 +0000queue
https://gateoverflow.in/156465/queue
A queue is implemented using two stack A and B. Consider the following code void enqueue(int value)<br />
<br />
{<br />
<br />
While (!B.is Empty())<br />
<br />
A.push(B.Pop());<br />
<br />
A. push (value);<br />
<br />
}<br />
<br />
int dequeue ()<br />
<br />
{<br />
<br />
While (!A.is Empty())<br />
<br />
{X}<br />
<br />
return B.Pop();<br />
<br />
}<br />
<br />
if enqueue is implemented using two stacks A & B With operation Push ,Pop and is empty of stacks then find the missing statement X to implement dequeue operation of the queue .<br />
<br />
A)<br />
<br />
A.Push(B.Pop());<br />
<br />
B)<br />
<br />
B.Push(A.Pop());<br />
<br />
C)<br />
<br />
A.Pop(B. Push ());<br />
<br />
D)<br />
<br />
B.Pop(A. Push ());<br />
<br />
what is difference between option b,d???DShttps://gateoverflow.in/156465/queueSun, 01 Oct 2017 06:11:41 +0000Queue
https://gateoverflow.in/155419/queue
<p><strong>If (rear==maxsize-1) </strong></p>
<p><strong>rear=0; </strong></p>
<p><strong>else rear=rear+1; </strong></p>
<p>is required in circular queue or deque ??</p>
<p> </p>
<p>I think it is circular queue but ans is deque...plzzz make me out.. </p>DShttps://gateoverflow.in/155419/queueTue, 26 Sep 2017 15:25:07 +0000Circular Queue
https://gateoverflow.in/146081/circular-queue
<p><img alt="" src="http://gateoverflow.in/?qa=blob&qa_blobid=18039375305392402081"></p>
<p>a)a_cb_</p>
<p>b)_abc_</p>
<p>c)abc_ _</p>
<p>d)_ab_c</p>Programminghttps://gateoverflow.in/146081/circular-queueMon, 21 Aug 2017 12:17:31 +0000queue
https://gateoverflow.in/134976/queue
<p><strong> The initial configuration of queue is a, b, c, d. ‘a’ is at the front. To get the configuration d, c, b, a how many deletions and additions required:</strong></p>
<p><strong>(A) 2 deletions, 3 additions </strong></p>
<p><strong>(B) 3 deletions, 2 additions</strong></p>
<p><strong>(C) 3 deletions, 4 additions </strong></p>
<p><strong>(D) 3 deletions, 3 additions</strong></p>Programminghttps://gateoverflow.in/134976/queueTue, 27 Jun 2017 15:56:34 +0000#Number of Elements in Circular Queues and Simple Queues #Doubt
https://gateoverflow.in/133910/%23number-elements-circular-queues-and-simple-queues-%23doubt
How many elements a simple queue and a circular queue both of size N can accommodates ?<br />
<br />
( A ) N and N respectively.<br />
<br />
( B ) N-1 and N-1 respectively.<br />
<br />
( C ) N and N-1 respectively.<br />
<br />
( D ) N-1 and N respectively.DShttps://gateoverflow.in/133910/%23number-elements-circular-queues-and-simple-queues-%23doubtMon, 19 Jun 2017 16:36:06 +0000#GateForum Correspondence Course (Page# 131, Q# 7), #Queue
https://gateoverflow.in/133909/%23gateforum-correspondence-course-page%23-131-q%23-7-%23queue
Which of the following data structure may give overflow error, even though the current number of element in it is less than its size ?<br />
<br />
(A) Simple Queue<br />
<br />
(B) Circular Queue<br />
<br />
(C) Stack<br />
<br />
(D) None of theseDShttps://gateoverflow.in/133909/%23gateforum-correspondence-course-page%23-131-q%23-7-%23queueMon, 19 Jun 2017 16:23:12 +0000Linked List implementation of Queue
https://gateoverflow.in/132554/linked-list-implementation-of-queue
Which of the following is true about linked list implementation of queue?<br />
(a) In push operation, if new nodes are inserted at the beginning of linked list, then in pop operation, nodes must be removed from end.<br />
(b) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be<br />
removed from the beginning. <br />
(c) Both of the above<br />
(d) None of the above<br />
<br />
Answer is (C)<br />
<br />
But my doubt here is that:-<br />
<br />
If we are allowed to use only singly linked list then option a) will take O(n) time to remove a node from the end of the linked list. So, in this case i.e. in case of singly linked list with O(1) TC answer should be (b)<br />
<br />
But If we are allowed to use doubly linked list then answer should be C only<br />
<br />
ryt?Programminghttps://gateoverflow.in/132554/linked-list-implementation-of-queueSat, 10 Jun 2017 13:27:53 +0000GATE2017-2-13
https://gateoverflow.in/118253/gate2017-2-13
A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed in $O(1)$ time?<br />
<br />
(I) Next pointer of front node points to the rear node.<br />
<br />
(II) Next pointer of rear node points to the front node.<br />
<br />
(A) (I) only.<br />
<br />
(B) (II) only.<br />
<br />
(C) Both (I) and (II).<br />
<br />
(D) Neither (I) nor (II).DShttps://gateoverflow.in/118253/gate2017-2-13Tue, 14 Feb 2017 12:24:37 +0000self doubt
https://gateoverflow.in/112319/self-doubt
<p>A <strong>Queue</strong> could be implemented using two <strong>Stacks</strong>.</p>
<p>So what will be the time complexity for insertion and deletion in this queue?</p>Programminghttps://gateoverflow.in/112319/self-doubtSat, 28 Jan 2017 12:57:31 +0000Made Easy FLT1 Circular Queue
https://gateoverflow.in/108756/made-easy-flt1-circular-queue
<p><img alt="" height="379" src="http://gateoverflow.in/?qa=blob&qa_blobid=17660484961348139063" width="728"></p>
<p>Doubt: dequeue really deletes the element or just moves the pointer? I'm not getting the answer.</p>DShttps://gateoverflow.in/108756/made-easy-flt1-circular-queueSat, 21 Jan 2017 18:05:54 +0000Queue Time Complexity
https://gateoverflow.in/98717/queue-time-complexity
" Time Complexity of Dequeue will be $ \leq $Time complexity of Enqueue operations "<br />
<br />
Justify the above statementDShttps://gateoverflow.in/98717/queue-time-complexitySat, 31 Dec 2016 11:54:09 +0000Queue
https://gateoverflow.in/75997/queue
<p><img alt="" height="126" src="http://gateoverflow.in/?qa=blob&qa_blobid=6322763459164278512" width="692">A queue is a particular kind of abstract data type. Enqueue and Dequeue makes the queue FIFO data structure. There are several efficient implementations of FIFO queues. An efficient implementation is one which can perform the operations of enququeing and dequeueing in O(1) time. The best choice is :</p>
<p>a] DLL c] SLL</p>
<p>b] Dynamic Array d] any one of these</p>Programminghttps://gateoverflow.in/75997/queueSat, 22 Oct 2016 23:48:03 +0000GATE 2016-1-41
https://gateoverflow.in/39684/gate-2016-1-41
<p>Let $Q$ denote a queue containing sixteen numbers and $S$ be an empty stack. Head(Q) returns the element at the head of the queue $Q$ without removing it from $Q$. Similarly Top (S) returns the element at the top of $S$ without removing it from $S$. Consider the algorithm given below.</p>
<pre class="prettyprint lang-c_cpp">
while Q is not Empty do
if S is Empty OR Top(S) ≤ Head (Q) then
x:= Dequeue (Q);
Push (S, x);
else
x:= Pop(S);
Enqueue (Q, x);
end
end</pre>
<p>The maximum possible number of iterations of the <strong>while</strong> loop in the algorithm is _______.</p>
<p> </p>
<p> </p>
DShttps://gateoverflow.in/39684/gate-2016-1-41Fri, 12 Feb 2016 14:12:02 +0000GATE 2016-1-10
https://gateoverflow.in/39667/gate-2016-1-10
<p><span style="line-height: 1.6;">A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is </span><strong style="line-height: 1.6;">CORRECT</strong><span style="line-height: 1.6;"> ($n$ refers to the number of items in the queue) ?</span></p>
<ol style="list-style-type: upper-alpha;">
<li>Both operations can be performed in $O(1)$ time.</li>
<li>At most one operation can be performed in $O(1)$ time but the worst case time for the operation will be $\Omega (n)$.</li>
<li>The worst case time complexity for both operations will be $\Omega (n)$.</li>
<li>Worst case time complexity for both operations will be $\Omega (\log n)$</li>
</ol>
DShttps://gateoverflow.in/39667/gate-2016-1-10Fri, 12 Feb 2016 14:03:56 +0000Implementing Queue with only one pointer
https://gateoverflow.in/29807/implementing-queue-with-only-one-pointer
Which of the following statement is/are correct?<br />
<br />
1. If we use only Front pointer in queue, then insertion takes O(n) time while deletion in O(1) time.<br />
<br />
2. If we use only Rear pointer in queue, then insertion is O(1) and deletion is not possible.DShttps://gateoverflow.in/29807/implementing-queue-with-only-one-pointerMon, 07 Dec 2015 09:25:59 +0000ISRO2014-36
https://gateoverflow.in/17423/isro2014-36
<p>Consider a standard Circular Queue implementation (which has the same condition for Queue Full and Queue Empty) whose size is $11$ and the elements of the queue are $q[0], q[1], \ldots q[10]$.</p>
<p>The front and rear pointers are initialized to point at $q[2]$. In which position will the ninth element be added?</p>
<ol style="list-style-type: upper-alpha;">
<li>$q[0]$</li>
<li>$q[1]$</li>
<li>$q[9]$</li>
<li>$q[10]$</li>
</ol>
DShttps://gateoverflow.in/17423/isro2014-36Wed, 23 Sep 2015 10:41:46 +0000solve
https://gateoverflow.in/5049/solve
<p>Suppose that stacks and queues are provided as opaque data types, offering only operations to add elements, to remove elements, and to test for emptiness. Suppose that a programmer wants to count the number of elements in a given stack or queue $C$, which is currently in some state $t$, using only one auxiliary stack or queue $D$. The structures $C$ and $D$ can be used in any way possible based on the methods they offer, but $C$ must be restored to its state $t$ after counting its elements. Counting elements as described above is possible for which of the following data types?</p>
<p><span style="line-height: 1.6;">(1) $C$ is a queue and $D$ is a queue.</span></p>
<p><span style="line-height: 1.6;">(2) $C$ is a stack and $D$ is a stack.</span></p>
<p><span style="line-height: 1.6;">(3) $C$ is a queue and $D$ is a stack.</span></p>
<ol style="list-style-type: lower-alpha;">
<li><span style="line-height: 1.6;">None</span></li>
<li><span style="line-height: 1.6;">$1$ and $2$ only.</span></li>
<li><span style="line-height: 1.6;">$1$ and $3$ only.</span></li>
<li><span style="line-height: 1.6;">$1$, $2$ and $3$.</span></li>
</ol>
<p> </p>
<p> </p>
<p><img alt="" src="http://gateoverflow.in/?qa=blob&qa_blobid=1456831654079577820" style="height:800px; width:600px"></p>
DShttps://gateoverflow.in/5049/solveThu, 11 Dec 2014 04:51:17 +0000GATE2007-IT-30
https://gateoverflow.in/3463/gate2007-it-30
<p>Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:</p>
<ol style="list-style-type:lower-roman">
<li>isEmpty (Q) — returns true if the queue is empty, false otherwise.</li>
<li>delete (Q) — deletes the element at the front of the queue and returns its value.</li>
<li>insert (Q, i) — inserts the integer i at the rear of the queue.</li>
</ol>
<p>Consider the following function:</p>
<pre class="prettyprint lang-c_cpp">
void f (queue Q) {
int i ;
if (!isEmpty(Q)) {
i = delete(Q);
f(Q);
insert(Q, i);
}
}</pre>
<p>What operation is performed by the above function f ?</p>
<ol style="list-style-type: upper-alpha;">
<li>Leaves the queue Q unchanged</li>
<li>Reverses the order of the elements in the queue Q</li>
<li>Deletes the element at the front of the queue Q and inserts it at the rear keeping the other elements in the same order</li>
<li>Empties the queue Q</li>
</ol>DShttps://gateoverflow.in/3463/gate2007-it-30Thu, 30 Oct 2014 04:11:15 +0000GATE1996-1.12
https://gateoverflow.in/2716/gate1996-1-12
<p>Consider the following statements:</p>
<ol style="list-style-type:lower-roman">
<li>
<p>First-in-first out types of computations are efficiently supported by STACKS.</p>
</li>
<li>
<p>Implementing LISTS on linked lists is more efficient than implementing LISTS on an array for almost all the basic LIST operations.</p>
</li>
<li>
<p>Implementing QUEUES on a circular array is more efficient than implementing QUEUES on a linear array with two indices.</p>
</li>
<li>
<p>Last-in-first-out type of computations are efficiently supported by QUEUES.</p>
</li>
</ol>
<p> </p>
<p> </p>
<ol style="list-style-type:upper-alpha">
<li>(ii) and (iii) are true</li>
<li>(i) and (ii) are true</li>
<li>(iii) and (iv) are true</li>
<li>(ii) and (iv) are true</li>
</ol>
<p> </p>DShttps://gateoverflow.in/2716/gate1996-1-12Thu, 09 Oct 2014 23:31:49 +0000GATE1994_26
https://gateoverflow.in/2522/gate1994_26
<p style="text-align:justify">A queue $Q$ containing $n$ items and an empty stack $S$ are given. It is required to transfer all the items from the queue to the stack, so that the item at the front of queue is on the TOP of the stack, and the order of all other items are preserved. Show how this can be done in $O(n)$ time using only a constant amount of additional storage. Note that the only operations which can be performed on the queue and stack are Delete, Insert, Push and Pop. Do not assume any implementation of the queue or stack.</p>
DShttps://gateoverflow.in/2522/gate1994_26Mon, 06 Oct 2014 01:06:03 +0000GATE2006-49
https://gateoverflow.in/1826/gate2006-49
<p>An implementation of a queue Q, using two stacks S1 and S2, is given below: </p>
<pre class="prettyprint lang-c_cpp">
void insert (Q, x) {
push (S1, x);
}
void delete (Q) {
if (stack-empty(S2)) then
if (stack-empty(S1)) then {
print(“Q is empty”);
return;
}
else while (!(stack-empty(S1))){
x=pop(S1);
push(S2,x);
}
x=pop(S2);
}</pre>
<p>let $n$ <em>insert</em> and $ m(\leq n)$ <em>delete</em> operations be performed in an arbitrary order on an empty queue Q. Let $x$ and $y$ be the number of <em>push</em> and <em>pop</em> operations performed respectively in the process. Which one of the following is true for all $m$ and $n$?</p>
<ol style="list-style-type: upper-alpha;">
<li>$ n+m\leq x<2n $ and $2m\leq y\leq n+m $</li>
<li>$ n+m\leq x<2n $ and $2m\leq y\leq 2n $</li>
<li>$ 2m\leq x<2n $ and $2m\leq y\leq n+m $</li>
<li>$ 2m\leq x<2n $ and $2m\leq y\leq 2n $</li>
</ol>DShttps://gateoverflow.in/1826/gate2006-49Fri, 26 Sep 2014 20:54:09 +0000GATE2012_35
https://gateoverflow.in/1756/gate2012_35
<p>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 <em>queue full</em> and <em>queue empty</em> are
<br>
<br>
(A)</p>
<p><em>full:</em> (REAR+1) mod n == FRONT</p>
<p><em>empty:</em> REAR == FRONT$</p>
<p>(B)</p>
<p><em>full:</em> (REAR+1) mod n == FRONT</p>
<p><em>empty:</em> (FRONT+1) mod n == REAR</p>
<p>(C)</p>
<p><em>full:</em> REAR == FRONT</p>
<p><em>empty:</em> (REAR+1) mod n == FRONT</p>
<p>(D)</p>
<p><em>full: </em>(FRONT+1) mod n == REAR</p>
<p><em>empty:</em> REAR == FRONT</p>DShttps://gateoverflow.in/1756/gate2012_35Fri, 26 Sep 2014 13:54:32 +0000GATE2001-2.16
https://gateoverflow.in/734/gate2001-2-16
<p>What is the minimum number of stacks of size $n$ required to implement a queue of size $n$?</p>
<ol style="list-style-type:upper-alpha">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
</ol>DShttps://gateoverflow.in/734/gate2001-2-16Mon, 15 Sep 2014 00:04:48 +0000GATE1992-09
https://gateoverflow.in/588/gate1992-09
<p>Suggest a data structure for representing a subset $S$ of integers from $1$ to $n$. Following operations on the set $S$ are to be performed in constant time (independent of cardinality of $S$).</p>
<table border="0" cellpadding="1" cellspacing="1" style="width:500px">
<tbody>
<tr>
<td style="width:189px">
<p>(i). MEMBER (X):</p>
</td>
<td style="width:298px">Check whether $X$ is in the set $S$ or not</td>
</tr>
<tr>
<td style="width:189px">(ii). FIND-ONE(S):</td>
<td style="width:298px">If $S$ is not empty, return one element of the set $S$ (any arbitrary element will do)</td>
</tr>
<tr>
<td style="width:189px">(iii). ADD (X):</td>
<td style="width:298px">Add integer $X$ to set $S$</td>
</tr>
<tr>
<td style="width:189px">(iv). DELETE (X):</td>
<td style="width:298px">Delete integer $X$ from $S$.</td>
</tr>
</tbody>
</table>
<p> </p>
<p>Give pictorial examples of your data structure. Give routines for these operations in an English like language. You may assume that the data structure has been suitable initialized. Clearly state your assumptions regarding initialization.</p>
<p> </p>
<p> </p>DShttps://gateoverflow.in/588/gate1992-09Sat, 13 Sep 2014 12:59:16 +0000GATE2013-44
https://gateoverflow.in/61/gate2013-44
<p>Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.
<br>
</p>
<pre class="prettyprint lang-c_cpp">
MultiDequeue(Q){
m = k
while (Q is not empty) and (m > 0) {
Dequeue(Q)
m = m – 1
}
}</pre>
<p>
<br>
<br>
What is the worst case time complexity of a sequence of $n$ queue operations on an initially empty
<br>
queue?
<br>
<br>
(A) $Θ(n)$
<br>
<br>
(B) $Θ(n + k)$
<br>
<br>
(C) $Θ(nk)$
<br>
<br>
(D) $Θ(n^2)$</p>DShttps://gateoverflow.in/61/gate2013-44Thu, 07 Aug 2014 21:02:08 +0000