Stack: GATE CS Previous Year Questions

Stack · Data Structures

13 questions · asked in 8 of 27 years (2000–2026)

MCQ 10 · MSQ 2 · NAT 11-mark 11 · 2-mark 2

2000Questions per year2026

Questions 1–5 of 13

Q1GATE 2025 (Session 2)2 marksMSQ
Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct.
We wish to augment the stack data structure with an O(1)O(1) time MIN operation that returns a pointer to the record with the smallest key present in the stack

1) without deleting the corresponding record, and
2) without increasing the complexities of the standard stack operations.

Which one or more of the following approach(es) can achieve it?

One or more options are correct.

Q2GATE 2024 (Session 1)1 markNAT
Consider the operator precedence and associativity rules for the integer arithmetic operators given in the table below.
OperatorPrecedenceAssociativity+HighestLeft−HighRight∗MediumRight/LowRight\begin{array}{|c|l|l|} \hline Operator & Precedence & Associativity \\ \hline+ & Highest & Left \\ \hline- & High & Right \\ \hline* & Medium & Right \\ \hline / & Low & Right \\ \hline \end{array}
The value of the expression 3+1+5∗2/7+2−4−7−6/23+1+5 * 2 / 7+2-4-7-6 / 2 as per the above rules is _____

Q3GATE 2024 (Session 2)2 marksMSQ
Let S1 and S2 be two stacks. S1 has capacity of 4 elements. S2 has capacity of 2 elements. S1 already has 4 elements: 100, 200, 300, and 400, whereas S2 is empty, as shown below.

400(Top)300200100\begin{array}{|c|} \hline 400 (Top) \\ \hline 300 \\ \hline 200\\ \hline 100 \\ \hline \end{array}
Stack S1

\begin{array}{|c|} \hline \\ \hline \\ \hline \end{array}
Stack S2

Only the following three operations are available:

PushToS2: Pop the top element from S1 and push it on S2.
PushToS1: Pop the top element from S2 and push it on S1.
GenerateOutput: Pop the top element from S1 and output it to the user.

Note that the pop operation is not allowed on an empty stack and the push operation is not allowed on a full stack.

Which of the following output sequences can be generated by using the above operations?

One or more options are correct.

Q4GATE 2015 (Session 3)1 markMCQ−0.33 if wrong
The result evaluating the postfix expression 10 5 + 60 6 / * 8 - is

Q5GATE 20071 markMCQ−0.33 if wrong
Consider the following C program:
 #include < stdio.h >

           #define EOF -1
           void push (int); /* push the argument on the stack */
           int pop  (void); /* pop the top of the stack */
           void flagError ();
           int main ()
          {         int c, m, n, r;
                     while ((c = getchar ()) != EOF)
                    { if  (isdigit (c) )
                               push (c);
                     else if ((c == '+') || (c == '*'))
                    {          m = pop ();
                                n = pop ();
                                r = (c == '+') ? n + m : n*m;
                                push (r);
                      }
                      else if (c != ' ')
                               flagError ();
             }
              printf("% c", pop ());
}

What is the output of the program for the following input?
5 2 * 3 3 2 + * +

Keep practising

Topics in Data Structures

All CS topics ›