Skip to content

Beta · Data may be lost.Your data may be reset or lost.

GateBrew
← GATE CSE 2016 Set 1
Questions

Q41

NAT2 marksData structuresHard

Let QQ denote a queue containing sixteen numbers and SS be an empty stack. Head(Q)Head(Q) returns the element at the head of the queue QQ without removing it from QQ. Similarly Top(S)Top(S) returns the element at the top of SS without removing it from SS. 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 _______.

Sign in to save attempts.

The solution is hidden while you attempt this question. It opens once you check or show the answer.