Queues questions

Q50

GATE CS 2026 CS-2Linear Data StructuresMSQ2 marks
Consider a stack SS and a queue QQ. Both of them are initially empty and have the capacity to store ten elements each. The elements 1, 2, 3, 4, and 5 arrive one by one, in that order. When an element arrives, it is assigned either to SS (pushed on SS) or to QQ (enqueued to QQ). Once all the five elements are stored, the output is generated in two steps. First, stack S is emptied by popping all elements. Then queue QQ is emptied by dequeueing all elements. The output obtained by following this process is 4  3  1  2  54 \; 3 \; 1 \; 2 \; 5.

Given the output, the objective is to predict whether an element was assigned to SS or QQ.

Which of the following options is/are possible valid assignment(s) of the elements?

Note: In the options, the notation xSxS denotes that element xx was assigned to SS and yQyQ denotes that element yy was assigned to QQ.
More than one option can be correct.
Show answer without attempting

Answer: A, B

Q59

GATE CS 2023 CSLinear Data StructuresNAT2 marks
Consider a sequence aa of elements a0=1,a1=5,a2=7,a3=8,a4=9a_0 = 1, a_1 = 5, a_2 = 7, a_3 = 8, a_4 = 9, and a5=2a_5 = 2. The following operations are performed on a stack SS and a queue QQ, both of which are initially empty.

I: push the elements of aa from a0a_0 to a5a_5 in that order into SS.
II: enqueue the elements of aa from a0a_0 to a5a_5 in that order into QQ.
III: pop an element from SS.
IV: dequeue an element from QQ.
V: pop an element from SS.
VI: dequeue an element from QQ.
VII: dequeue an element from QQ and push the same element into SS.
VIII: Repeat operation VII three times.
IX: pop an element from SS.
X: pop an element from SS.

The top element of SS after executing the above operations is ____________.
Show answer without attempting

Answer: 8

Q62

GATE CS 2022 CSLinear Data StructuresNAT2 marks
Consider the queues Q1Q_1 containing four elements and Q2Q_2 containing none (shown as the Initial State in the figure). The only operations allowed on these two queues are Enqueue(Q, element) and Dequeue(Q). The minimum number of Enqueue operations on Q1Q_1 required to place the elements of Q1Q_1 in Q2Q_2 in reverse order (shown as the Final State in the figure) without using any additional storage is___________.
Question figure
Show answer without attempting

Answer: 0

Q21

GATE CS 2021 CS-1Linear Data StructuresNAT1 mark
Consider the following sequence of operations on an empty stack.
push(54); push(52); pop(); push(55); push(62); s = pop();
Consider the following sequence of operations on an empty queue.
enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q = dequeue();
The value of s + q is ______.
Show answer without attempting

Answer: 86

Q3

GATE CS 2018 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let nn denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail.

Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?
Question figure
Show answer without attempting

Answer: B

Q10

GATE CS 2016 CS-1Linear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (nn refers to the number of items in the queue)?
Show answer without attempting

Answer: A

Q41

GATE CS 2016 CS-1Linear Data StructuresNAT2 marks
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.
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
The maximum possible number of iterations of the while loop in the algorithm is ________.
Show answer without attempting

Answer: 256.0

Q44

GATE CS 2013 CSLinear Data StructuresMCQ2 marks−2/3 if wrong
Consider the following operation along with Enqueue and Dequeue operations on queues, where kk is a global parameter.
MultiDequeue(Q){
  m = k
  while (Q is not empty) and (m > 0) {
    Dequeue(Q)
    m = m – 1
  }
}
What is the worst case time complexity of a sequence of nn queue operations on an initially empty queue?
Show answer without attempting

Answer: A

Q35

GATE CS 2012 CSLinear Data StructuresMCQ2 marks−2/3 if wrong
Suppose a circular queue of capacity (n−1)(n - 1) elements is implemented with an array of nn 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 are
Show answer without attempting

Answer: A

0/90 correct0 marks

Related topics in Linear Data Structures