/* */ Click to Join Live Class with Shankar sir Call 9798158723

Data Structure MCQ - Stack


Q1.Process of inserting an element in stack is called ____________
  1. Create
  2. Evaluation
  3. Pop
  4. Push

Answer:- (D).
Explanations :Push operation allows users to insert elements in the stack. If the stack is filled completely and trying to perform push operation stack – overflow can happen.
Q2.Process of removing an element from stack is called __________
  1. Pop
  2. Create
  3. Push
  4. Evaluated

Answer:- (A).
Explanations :Elements in the stack are removed using pop operation. Pop operation removes the top most element in the stack i.e. last entered element.
Q3.Pushing an element into stack already having five elements and stack size of 5, then stack becomes ___________
  1. Underflow
  2. User flow
  3. Overflow
  4. Crash

Answer:- (C).
Explanations :The stack is filled with 5 elements and pushing one more element causes a stack overflow. This results in overwriting memory, code and loss of unsaved work on the computer.
Q4.Entries in a stack are “ordered”. What is the meaning of this statement?
  1. A collection of stacks is sortable
  2. The entries are stored in a linked list
  3. There is a Sequential entry that is one by one
  4. Stack entries may be compared with the ‘<‘ operation

Answer:- (C).
Explanations : In stack data structure, elements are added one by one using push operation. Stack follows LIFO Principle i.e. Last In First Out(LIFO).
Q5.Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some order). The maximum number of parentheses that appear on the stack AT ANY ONE TIME during the computation?
  1. 1
  2. 3
  3. 2
  4. 4 or more

Answer:- (C).
Explanations :In the entire parenthesis balancing method when the incoming token is a left parenthesis it is pushed into stack. A right parenthesis makes pop operation to delete the elements in stack till we get left parenthesis as top most element. 2 left parenthesis are pushed whereas one right parenthesis removes one of left parenthesis. 2 elements are there before right parenthesis which is the maximum number of elements in stack at run time.
Q6.The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
  1. AB+ CD*E – FG /**
  2. AB+ CD*E – FG /**
  3. AB + CDE * – * F *G /
  4. AB + CD* E – F **G

Answer:- (B).
Explanations :(((A+ B)*(C*D- E)*F) / G) is converted to postfix expression as
(AB+(*(C*D- E)*F )/ G)
(AB+CD*E-*F) / G
(AB+CD*E-*F * G/). Thus Postfix expression is AB+CD*E-*F*G/
Q7.The data structure required to check whether an expression contains balanced parenthesis is
  1. Stack
  2. Queue
  3. Tree
  4. Array

Answer:- (A).
Q8.Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing.
void fun(int n)
{
    Stack S;  // Say it creates an empty stack S
    while (n > 0)
    {
      // This line pushes the value of n%2 to stack S
      push(&S, n%2);
 
      n = n/2;
    }
 
    // Run while Stack S is not empty
    while (!isEmpty(&S))
      printf("%d ", pop(&S)); // pop an element from S and print it
}
  1. Prints binary representation of n in reverse order
  2. Prints binary representation of n
  3. Prints the value of Logn
  4. Prints the value of Logn in reverse order

Answer:- (B).
Q9.Which one of the following is an application of Stack Data Structure
  1. Managing function calls
  2. The stock span problem
  3. Arithmetic expression evaluation
  4. All of the above

Answer:- (D).
Q10.In a stack, if a user tries to remove an element from empty stack it is called _________.
  1. Underflow
  2. Empty collection
  3. Overflow
  4. Garbage Collection

Answer:- (A).
Explanations :In a stack, if a user tries to remove an element from empty stack it is called Underflow.