chapter
    Stacks, Queues and Linked Lists Practice Questions for GATE CS

    Solve 60+ Stacks, Queues and Linked Lists practice questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    Level 1: Warm-up

    An empty stack and an empty queue undergo the following operations:

    Stack: push(10), push(20), pop(), push(30)

    Queue: enqueue(10), enqueue(20), dequeue(), enqueue(30)

    Let be the sum of elements currently in the stack, and be the sum of elements currently in the queue. Which of the following correctly describes the relationship between and ?

    Question 2
    Level 1: Warm-up

    An augmented stack stores pairs of to achieve minimum queries. The current top pair in the stack is . If we push a new arbitrary integer element , the new top pair will be . What is the maximum possible value of ?

    Question 3
    Level 1: Warm-up

    A stack is initially empty. The following operations are performed in sequence:

    push(10), push(-5), pop(), push(-3), pop()

    What is the sum of the values returned by the two pop operations?

    Question 4
    Level 1: Warm-up

    An augmented stack stores pairs of . The stack currently contains the following pairs from bottom to top:

    If we perform push(3), what is the new top pair?

    Question 5
    Level 1: Warm-up

    Which of the following statements is TRUE regarding reversing a queue of elements into using ONLY Enqueue and Dequeue operations?

    Question 6
    Level 1: Warm-up

    Consider the following Assertion (A) and Reason (R):

    Assertion (A): In the two-queue reversal algorithm for elements, the total number of Enqueue operations performed on is .

    Reason (R): acts as both the destination for the elements from and the buffer for rotating the already placed elements.

    Select the correct option:

    Question 7
    Level 1: Warm-up

    Which of the following statements is TRUE regarding the reversal of a queue of elements into an empty queue using ONLY Enqueue and Dequeue operations on and ?

    Question 8
    Level 1: Warm-up

    Consider the following Assertion (A) and Reason (R):

    Assertion (A): In the two-queue reversal algorithm for elements, the total number of Dequeue operations performed on the destination queue is .

    Reason (R): For each of the elements moved from to , it must be cycled past the elements already in , requiring a number of Dequeue operations on equal to the current size of .

    Select the correct option:

    Question 9
    Level 1: Warm-up

    Match the operation with its minimum count when reversing an -element queue into an empty queue using ONLY Enqueue and Dequeue operations on and .

    List-I (Operation)

    P. Enqueue operations on

    Q. Dequeue operations on

    List-II (Count)

    Question 10
    Level 1: Warm-up

    Consider the following sequence of operations performed on an initially empty stack:

    push, push, pop, push, pop, pop

    A student claims that the stack becomes empty exactly 3 times during this sequence. What is the actual minimum number of times the stack becomes empty?

    Free preview ends here

    Login to view the complete practice questions and solutions

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Stacks, Queues and Linked Lists Practice Questions for GATE CS

    Solve 60+ Stacks, Queues and Linked Lists practice questions for GATE CS with answers and detailed solutions. Free sample questions below.

    Chapter Roadmap: Stacks, Queues, and Linked Lists

    Chapter Journey

    1. Stack Operations and Augmented Stacks
    Current Topic
    Focus: Mastering the Last-In-First-Out (LIFO) principle and step-by-step tracing.
    Key Skill: Optimizing stacks for constant-time minimum queries.
    2. Queue Operations, Reversal and Stack-Queue Interaction
    Focus: First-In-First-Out (FIFO) principle and simulating queues with stacks.
    Key Skill: Reversal algorithms and data structure interactions.
    3. Linked List Manipulation, Recursion and Complexity
    Focus: Pointer manipulation and recursive traversal.
    Key Skill: Time-space tradeoffs in linear data structures.
    Exam Weightage Hint: Stacks (0.41), Queues (0.41), Linked Lists (0.55). Linked lists carry the highest weight, but stack augmentation is a frequent, high-value target.

    Hero Concept: The Stack and Its Core Operations

    The Core Intuition

    A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. The element added most recently is the first one to be removed.

    TOP push / pop
    • push(x) Inserts element at the top.
    • pop() Removes and returns the top element.
    • peek() Returns the top element without removing it.
    • isEmpty() Checks if the stack contains no elements.
    Complexity: All standard stack operations execute in time complexity, regardless of the number of elements . This makes stacks indispensable for function call management, expression evaluation, and backtracking.

    Stacks, Queues and Linked Lists: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Programming and Data Structures MCQ

    An empty stack and an empty queue undergo the following operations:

    Stack: push(10), push(20), pop(), push(30)

    Queue: enqueue(10), enqueue(20), dequeue(), enqueue(30)

    Let be the sum of elements currently in the stack, and be the sum of elements currently in the queue. Which of the following correctly describes the relationship between and ?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is a bounding question testing the fundamental difference between LIFO (stack) and FIFO (queue) removal constraints.

    Step 1: Trace the Stack (LIFO).

    • push(10) [10]
    • push(20) [10, 20]
    • pop() removes 20 (top). Stack is [10]
    • push(30) [10, 30]
    • Sum .

    Step 2: Trace the Queue (FIFO).

    • enqueue(10) [10]
    • enqueue(20) [10, 20]
    • dequeue() removes 10 (front). Queue is [20]
    • enqueue(30) [20, 30]
    • Sum .

    Step 3: Compare and . , so .

    Answer:

    Question 2 · Programming and Data Structures MCQ

    An augmented stack stores pairs of to achieve minimum queries. The current top pair in the stack is . If we push a new arbitrary integer element , the new top pair will be . What is the maximum possible value of ?

    1. A.

    2. B.

      9

    3. C.

      3

    4. D.

      0

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is an observation question testing the boundary condition of the augmented stack's minimum tracking logic.

    Step 1: Recall the rule for the pair approach: when pushing , the new minimum is calculated as .

    Step 2: The current minimum (the second element of the top pair) is 3.

    Step 3: Therefore, .

    Step 4: By the definition of the minimum function, can never exceed 3, regardless of how large is. The maximum possible value for is exactly 3.

    Answer: 3

    Question 3 · Programming and Data Structures MCQ

    A stack is initially empty. The following operations are performed in sequence:

    push(10), push(-5), pop(), push(-3), pop()

    What is the sum of the values returned by the two pop operations?

    1. A.

      8

    2. B.

      -8

    3. C.

      2

    4. D.

      -2

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a basic LIFO tracing question testing careful handling of negative numbers during sequential operations.

    Step 1: push(10) Stack: [10]

    Step 2: push(-5) Stack: [10, -5]

    Step 3: pop() Removes and returns -5. Stack: [10]

    Step 4: push(-3) Stack: [10, -3]

    Step 5: pop() Removes and returns -3. Stack: [10]

    Step 6: Sum the returned values: .

    Answer: -8

    Question 4 · Programming and Data Structures MCQ

    An augmented stack stores pairs of . The stack currently contains the following pairs from bottom to top:

    If we perform push(3), what is the new top pair?

    1. A.

      (3, 3)

    2. B.

      (3, 5)

    3. C.

      (3, 10)

    4. D.

      (8, 3)

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is an augmented stack question. When pushing a new value, the current_min is updated as min(new_value, previous_min).

    Step 1: Identify the current state.

    • Stack from bottom to top: (10, 10), (5, 5), (8, 5)
    • Current top pair: (8, 5)
    • Current minimum: 5 (from the top pair's second element)

    Step 2: Perform push(3).

    • New value: 3
    • Previous minimum: 5
    • New minimum: min(3, 5) = 3

    Step 3: Form the new top pair.

    • New pair: (value, new_min) = (3, 3)

    Step 4: Update the stack.

    • Stack from bottom to top: (10, 10), (5, 5), (8, 5), (3, 3)
    • New top pair: (3, 3)

    Answer: A

    Question 5 · Programming and Data Structures MCQ

    Which of the following statements is TRUE regarding reversing a queue of elements into using ONLY Enqueue and Dequeue operations?

    1. A.

      The time complexity of the reversal is strictly bounded by .

    2. B.

      Every element is dequeued from exactly once.

    3. C.

      An auxiliary stack is used to temporarily store elements during rotation.

    4. D.

      The total number of enqueue operations on is exactly .

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question testing the time complexity and operation constraints of two-queue reversal.

    Step 1: Analyze the constraint. The problem specifies "using ONLY Enqueue and Dequeue operations". This explicitly forbids auxiliary data structures like stacks.

    Step 2: Evaluate option A. Reversing a queue using two queues requires cycling elements, which strictly bounds the time complexity at , not .

    Step 3: Evaluate option B. acts strictly as the source. To move all elements to , every element must be dequeued from exactly once. This is true.

    Step 4: Evaluate option C. This violates the "ONLY Enqueue and Dequeue" constraint.

    Step 5: Evaluate option D. receives elements from , plus additional enqueues during rotation. The total enqueues on is , not .

    Answer: B

    Question 6 · Programming and Data Structures MCQ

    Consider the following Assertion (A) and Reason (R):

    Assertion (A): In the two-queue reversal algorithm for elements, the total number of Enqueue operations performed on is .

    Reason (R): acts as both the destination for the elements from and the buffer for rotating the already placed elements.

    Select the correct option:

    1. A.

      Both A and R are true, and R is the correct explanation of A.

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A.

    3. C.

      A is true, but R is false.

    4. D.

      A is false, but R is true.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a construction question validating the logical relationship between the roles of and .

    Step 1: Construct the mental model of the two-queue reversal algorithm. is the source, is the destination and rotation buffer.

    Step 2: Evaluate Assertion (A). For each of the elements moved from , the elements already in must be cycled (dequeued and enqueued back to ) to maintain the reversed order. The total enqueues on sum to . Assertion (A) is true.

    Step 3: Evaluate Reason (R). indeed absorbs all elements from and also handles the rotation enqueues. Reason (R) is true.

    Step 4: Check the explanatory link. Reason (R) perfectly describes the mechanical roles that cause the mathematical sum in Assertion (A). Therefore, R is the correct explanation of A.

    Answer: A

    Question 7 · Programming and Data Structures MCQ

    Which of the following statements is TRUE regarding the reversal of a queue of elements into an empty queue using ONLY Enqueue and Dequeue operations on and ?

    1. A.

      The time complexity is because each element is transferred directly from to .

    2. B.

      The algorithm requires an auxiliary stack to temporarily hold elements during cycling.

    3. C.

      The total number of Dequeue operations performed on is exactly .

    4. D.

      The total number of Enqueue operations performed on is .

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is a bounding question testing the constraints and mechanics of two-queue reversal.

    Step 1: Analyze the constraint. The problem specifies "using ONLY Enqueue and Dequeue operations on and ". This explicitly forbids auxiliary data structures like stacks or arrays.

    Step 2: Evaluate the roles. starts with elements and acts strictly as the source. It only loses elements via Dequeue operations. It never receives elements back.

    Step 3: Bound the operations. To empty completely, exactly Dequeue operations must be performed on it. Therefore, the statement "The total number of Dequeue operations performed on is exactly " is true.

    Step 4: Evaluate other options. Option A is false because cycling requires time. Option B is false because it violates the "ONLY Enqueue and Dequeue" constraint. Option D is false because receives 0 Enqueue operations.

    Answer: C

    Question 8 · Programming and Data Structures MCQ

    Consider the following Assertion (A) and Reason (R):

    Assertion (A): In the two-queue reversal algorithm for elements, the total number of Dequeue operations performed on the destination queue is .

    Reason (R): For each of the elements moved from to , it must be cycled past the elements already in , requiring a number of Dequeue operations on equal to the current size of .

    Select the correct option:

    1. A.

      Both A and R are true, and R is the correct explanation of A.

    2. B.

      Both A and R are true, but R is NOT the correct explanation of A.

    3. C.

      A is true, but R is false.

    4. D.

      A is false, but R is true.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a construction question validating the logical relationship between the cycling mechanics and operation counts.

    Step 1: Construct the mental model of the two-queue reversal algorithm.

    • starts with elements. It acts strictly as the source.
    • starts empty. It acts as the destination and the rotation buffer.

    Step 2: Evaluate Reason (R). When the -th element is moved from to , there are already elements in . To place the new element at the front (relative to the final reversed order), the existing elements must be cycled. Cycling elements requires exactly Dequeue operations on . Reason (R) is true.

    Step 3: Evaluate Assertion (A). The total number of Dequeue operations on is the sum of Dequeues for each of the elements: . Assertion (A) is true.

    Step 4: Check the explanatory link. Reason (R) perfectly describes the mechanical cause that directly results in the mathematical sum stated in Assertion (A). Therefore, R is the correct explanation of A.

    Answer: A

    Question 9 · Programming and Data Structures MCQ

    Match the operation with its minimum count when reversing an -element queue into an empty queue using ONLY Enqueue and Dequeue operations on and .

    List-I (Operation)

    P. Enqueue operations on

    Q. Dequeue operations on

    List-II (Count)

    1. A.

      P-1, Q-2

    2. B.

      P-2, Q-1

    3. C.

      P-1, Q-3

    4. D.

      P-3, Q-2

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: In the standard two-queue reversal algorithm, acts strictly as the source and as the destination.

    Step 1: Since is only the source, elements are only removed from it. Thus, it undergoes exactly Dequeue operations.

    Step 2: No elements are ever added back to . Therefore, the number of Enqueue operations on is exactly .

    Answer: P matches with 1, and Q matches with 2.

    Question 10 · Programming and Data Structures MCQ

    Consider the following sequence of operations performed on an initially empty stack:

    push, push, pop, push, pop, pop

    A student claims that the stack becomes empty exactly 3 times during this sequence. What is the actual minimum number of times the stack becomes empty?

    1. A.

      3

    2. B.

      2

    3. C.

      1

    4. D.

      0

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This is a contradiction question testing precise step-by-step tracing against a flawed mental model of stack emptiness.

    Step 1: Trace the stack size step-by-step.

    • push size 1
    • push size 2
    • pop size 1
    • push size 2
    • pop size 1
    • pop size 0 (Stack is empty. Count = 1)

    Step 2: Evaluate the student's claim. The student likely counted every pop operation as an event that makes the stack empty.

    Step 3: The stack only reaches size 0 once, at the very end.

    Answer: 1

    More practice questions in this unit