GateAI
Linear Structures, Trees and Heaps

GATE CSE 2014 Set 2 · Q41

MCQ2 marksMedium

Time

Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack\text{with respect to this modified stack}?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: C) A queue can be implemented where ENQUEUE takes a sequence of three instructions and DEQUEUE takes a single instruction.

Linear Structures, Trees and Heaps

A queue follows First-In, First-Out (FIFO) order, whereas a stack follows Last-In, First-Out (LIFO) order.

We can implement a queue using the modified stack such that the front of the queue is always at the top of the stack:

  • DEQUEUE operation: Since the oldest element (front of the queue) is maintained at the top of the stack, DEQUEUE simply performs a single POP instruction (1 instruction).

  • ENQUEUE(x) operation: To insert a new element at the bottom of the stack (rear of the queue) while keeping the oldest at the top:

    1. REVERSE (the newest elements move to the top)

    2. PUSH(x) (push the new element)

    3. REVERSE (restore order so that the oldest element is back at the top)

    This takes a sequence of 3 instructions.

Thus, a queue can be implemented where ENQUEUE takes a sequence of 3 instructions and DEQUEUE takes a single instruction, making (C) the correct statement.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Linear Structures, Trees and Heaps previous year question is Q41 of the GATE CSE 2014 Set 2 paper. Find more GATE CSE PYQs on Linear Structures, Trees and Heaps in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Linear Structures, Trees and Heaps PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Linear Structures, Trees and Heaps in GATE CSE

Linear Structures, Trees and Heaps has 14 GATE CSE PYQs across 12 papers from 2012 to 2026. 4 of them are 2-mark MCQs like this one, and it is the only one in GATE CSE 2014 Set 2.

How GATE tests Linear Structures, Trees and Heaps

More from GATE CSE 2014 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2014 Set 2 · Q41 · MCQ

Suppose a stack implementation supports an instruction REVERSE, which reverses the order of elements on the stack, in addition to the PUSH and POP instructions. Which one of the following statements is TRUE with respect to this modified stack?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.