Consider the following sequence of operations on an empty stack.…

2025

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 ___________.

  1. A.

    86

  2. B.

    68

  3. C.

    24

  4. D.

    94

Attempted by 239 students.

Show answer & explanation

Correct answer: A

Explanation:

Let's construct an empty stack and do the operations.

Stack follows LIFO order.

1.Push(54) // (54)

2.Push(52) // (54,52)

3.Pop() // (54)

4.Push(55) //(54,55)

5.Push(62) //(54,55,62)

6.s=pop() // (54,55)

s=62; Let's construct an empty queue and do the operations.

Queue follows FIFO order.

1.Enqueue(21) // [21]

2.Enqueue(24) // [21,24]

3.Dequeue() // [24]

4.Enqueue(28) // [24,28]

5.Enqueue(32) // [24,28,32]

6.q=Dequeue() // [28,32] q=24; s+q=62+24 So, s+q=86 .

Alternative Way : Stack is last in first out data structure, so s = pop() = 62 Queue is first in first out data structure, so q = dequeue() = 24

Therefore, s+q = 62+24 = 86

Explore the full course: Coding For Placement