• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Stack Data Structure with Answers

Question 11

Consider the following C program: C
   #include 
           #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 + * +
  • 15
  • 25
  • 30
  • 150

Question 12

Suppose a stack is to be implemented with a linked list instead of an array. What would be the effect on the time complexity of the push and pop operations of the stack implemented using linked list (Assuming stack is implemented efficiently)?
  • O(1) for insertion and O(n) for deletion
  • O(1) for insertion and O(1) for deletion
  • O(n) for insertion and O(1) for deletion
  • O(n) for insertion and O(n) for deletion

Question 13

Consider n elements that are equally distributed in k stacks. In each stack, elements of it are arranged in ascending order (min is at the top in each of the stack and then increasing downwards). Given a queue of size n in which we have to put all n elements in increasing order. What will be the time complexity of the best known algorithm?
  • O(n logk)
  • O(nk)
  • O(n2)
  • O(k2)

Question 14

A priority queue Q is used to implement a stack S that stores characters. PUSH(C) is implemented as INSERT(Q, C, K) where K is an appropriate integer key chosen by the implementation. POP is implemented as DELETEMIN(Q). For a sequence of operations, the keys chosen are in

  • Non-increasing order

  • Non-decreasing order

  • strictly increasing order

  • strictly decreasing order

Question 15

Which of the following permutation can be obtained in the same order using a stack assuming that input is the sequence 5, 6, 7, 8, 9 in that order?
  • 7, 8, 9, 5, 6
  • 5, 9, 6, 7, 8
  • 7, 8, 9, 6, 5
  • 9, 8, 7, 5, 6

Question 16

The best data structure to check whether an arithmetic expression has balanced parenthesis is a
  • Queue
  • Stack
  • Tree
  • List

Question 17

The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse order, i.e., starting from G. The stack is popped five times and each element is inserted into a queue.Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is ________.
  • A
  • B
  • F
  • G

Question 18

If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack, the sequence of popped out values

  • 2,2,1,1,2

  • 2,2,1,2,2

  • 2,1,2,2,1

  • 2,1,2,2,2

Question 19

The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is popped from the stack. The popped item is

  • A

  • B

  • C

  • D

Question 20

Consider the following operations performed on a stack of size 5 : Push (a); Pop() ; Push(b); Push(c); Pop(); Push(d); Pop();Pop(); Push (e) Which of the following statements is correct?

  • Underflow occurs

  • Stack operations are performed smoothly

  • Overflow occurs

  • None of the above

There are 30 questions to complete.

Last Updated :
Take a part in the ongoing discussion