Queues questions

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

0/20 correct0 marks

Related topics in Linear Data Structures