Computer Sciences > GATE 2026 SET-2 > Data Structures
Consider a stack 𝑆 and a queue 𝑄. 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 𝑆 (pushed on 𝑆 ) or to 𝑄 (enqueued to 𝑄). 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 𝑄 is emptied by dequeueing all elements. The output obtained by following this process is 4 3 1 2 5 . Given the output, the objective is to predict whether an element was assigned to 𝑆 or 𝑄.
Which of the following options is/are possible valid assignment(s) of the elements?
Note: In the options, the notation π‘₯𝑆 denotes that element π‘₯ was assigned to 𝑆 and y𝑄 denotes that element 𝑦 was assigned to 𝑄.
A
1S, 2Q, 3S, 4S, 5Q
B
1Q, 2Q, 3S, 4S, 5Q
C
1Q, 2Q, 3Q, 4S, 5S
D
1S, 2S, 3S, 4Q, 5Q

Correct : a,b

Similar Questions

Which one of the following sequences when stored in an array at locations A[1],...,A[10] forms a max-heap?
#950 MCQ
Let SLLdel be a function that deletes a node in a singly-linked list given a pointer to the node and a pointer to the head of the list. Similarly, let DLLdel be...
#951 MCQ
An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let...
#957 MCQ

Related Topics

No tags found

Unique Visitor Count

Total Unique Visitors

Loading......