Stack Operations – Data Structure Questions and Answers

Data Structures & Algorithms Computer Science & Engineering

This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Stack Operations”.

1. Which of the following is not the application of stack?

A) A parentheses balancing program
B) Tracking of local variables at run time
C) Compiler Syntax Analyzer
D) Data Transfer between two asynchronous process

Explanation: The queue data structure is used to synchronise data transmission between the two asynchronous processes. The remaining programmes are all stack applications.

2. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. The maximum number of parentheses that appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
A) 1
B) 2
C) 3
D) 4 or more

Explanation: If the incoming token is a left capital letter, the entire parenthesis balancing process pushes it into the stack. A right parenthesis performs a pop operation on the elements in the stack, removing them one by one
until the left hyphen is the topmost element. Before the correct brackets appear, there are three elements in the stack. As a result, at runtime, the maximum number of components in the stack is 3.

3. 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?
A) 1
B) 2
C) 3
D) 4 or more

Explanation: If the incoming token is a left parenthesis, the entire bolded text balancing process pushes it into the stack. A right hyphen performs a pop operation on the elements in the stack, removing them one by one until the left hyphen is the topmost element. One right ellipsis eliminates one of the left square brackets, while two left hyphens are moved. Before the right square brackets, there are two elements, which is the maximum number of elements in the stack at run time.

4. What is the value of the postfix expression 6 3 2 4 + – *?
A) 1
B) 40
C) 74
D) -18

Explanation: The output of the postfix expression (6*(3-(2+4)) is -18.

5. Here is an infix expression: 4 + 3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. The maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?
A) 1
B) 2
C) 3
D) 4

Explanation: The symbols +, *, (, *) are put within the stack when the infix to postfix conversion is performed. During the conversion, a maximum of four symbols are found.

6. Process of inserting an element in stack is called ____________
A) Create
B) Push
C) Evaluation
D) Pop

Explanation: Users can insert elements into the stack using the push operation. Overflow will occur if the stack is fully full and a push operation is attempted.

7. Process of
removing an element from stack is called __________

A) Create
B) Push
C) Evaluation
D) Pop

Explanation: The pop operation is used to delete elements from the stack. The
pop operation removes the stack’s topmost element, i.e. the last entered
element.

8. In a stack, if a user tries to remove an element from an empty stack it is called _________

A) Underflow
B) Empty collection                                                                                                                                                        C)Overflow
D) Garbage Collection

Explanation: When a user performs a pop operation on an empty stack, underflow
occurs. When the stack is complete and the user performs a push operation, the
stack overflows. Garbage Collection is a technique for recovering memory that
has been occupied by no longer used items.

9. Pushing an element into stack already having five elements and
stack size of 5, then stack becomes ___________

A) Overflow
B) Crash
C) Underflow
D) User flow

Explanation: There are 5 elements in the stack, and adding one more causes the
stack to overflow. As a consequence, memory, code, and unsaved work on the
machine are overwritten.

10. Entries in a stack are “ordered”. What is the meaning of this
statement?

A) A collection of stacks is sortable
B) Stack entries may be compared with the ‘<‘ operation
C) The entries are stored in a linked list
D) There is a
Sequential entry that is one by one

Explanation: The elements of a stack data structure are added one by one using
the push operation. The Last In First Out (LIFO) principle is followed by the
stack (LIFO).

public relations
https://7e42fbb577c60b9e8209600831a683ad.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html
https://7e42fbb577c60b9e8209600831a683ad.safeframe.googlesyndication.com/safeframe/1-0-38/html/container.html

11. Which data structure is needed to convert infix notation to
postfix notation?

A) Branch
B) Tree
C) Queue
D) Stack

Explanation:  Infix expressions are converted to infix expressions using the Stack data structure.
speech with a postfix Stack is used to reverse the order of items in a list.
in the expression’s operators It also serves as a storage structure, as there is no other choice.
It is possible to print an operator before both of its operands have emerged.

12. The prefix form of A-B/ (C * D ^ E) is?
A) -/*^ACBDE
B) -ABCD*^DE
C) -A/B*C^DE
D) -A/BC*^DE

Explanation: Infix Expression is (A-B)/(C*D^E)
(-A/B)(C*D^E)
-A/B*C^DE. Thus prefix expression is -A/B*C^DE.

13. What is the result of the following operation?
Top (Push (S, X))
A) X
B) X+S
C) S
D) XS

Explanation: Push(S,X) is a function that moves the value X into the stack S. to the top ()
The value that was entered last is returned by the function. Finally, X made it into stack S.

14. The prefix form of an infix expression (p + q) – (r * t) is?
A) + pq – *rt
B) – +pqr * t
C) – +pq * rt
D) – + * pqrt

Explanation: Given Infix Expression is ((p+q)-(r*t))
(+pq)-(r*t)
(-+pq)(r*t)
-+pq*rt. Thus prefix expression is -+pq*rt.

15. Which data structure is used for implementing recursion?
A) Queue
B) Stack
C) Array
D) List

Explanation: The implementation of recursion is done with stacks.

 

 

 

 

 

16. The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
A) AB+ CD*E – FG /**
B) AB + CD* E – F **G /
C) AB + CD* E – *F *G /
D) AB + CDE * – * F *G /

Explanation: (((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/

17. The data structure required to check whether an expression
contains a balanced parenthesis is?

A) Stack
B) Queue
C) Array
D) Tree

Explanation: The stack is a basic data structure that uses the LIFO concept to add and remove components. A closed parenthesis pops out elements as an open parenthesis is pushed into the stack, until the top element of the stack is its corresponding open hyphen. Parenthesis are balanced if the stack is empty; otherwise, they are unbalanced.

18. What data structure would you mostly likely see in non recursive
implementation of a recursive algorithm?

A) Linked List
B) Stack
C) Queue
D) Tree

Explanation: The order in which the recursive method returns in recursive algorithms is the inverse of the order in which it goes forward during execution. The stack data structure is used by the compiler to implement recursion.
The values of local variables, parameters, and the return address are pushed into the stack at each recursion stage during the forwarding process. The stacked address is popped and used to execute the rest of the code during the backing-out process.

19. The process of accessing data stored in a serial access memory
is similar to manipulating data on a ________

A) Heap
B) Binary Tree
C) Array
D) Stack

Explanation: Data records are created and accessed sequentially in serial access memory, which stores them one after the other. The components of a stack data structure are accessed in a sequential order. Serial access memory is similar to the stack data structure.

20. The postfix form of A*B+C/D is?
A) *AB/CD+
B) AB*CD/+
C) A*BC+/D
D) ABCD+/*

Explanation: Infix expression is (A*B)+(C/D)
AB*+(C/D)
AB*CD/+. Thus postfix expression is AB*CD/+.

21. Which of the
following is not an inherent application of stack?

A) Reversing a string
B) Evaluation of postfix expression
C) Implementation of recursion
D) Job scheduling

Explanation: Stacks are not used for job scheduling.

22. The type of expression in which operator succeeds its operands
is?

A) Infix Expression
B) Prefix Expression
C) Postfix Expression
D) Both Prefix and Postfix Expressions

Explanation: The word “postfix expression” refers to an expression in which the operator comes after its operands. Prefix expression is an expression in which the operator comes before the operands. Infix expressions are those in which an operator appears between two operands.

23. Assume that the operators +,-, X are left associative and ^ is
right associative. The order of precedence (from highest to lowest) is ^, X, +,
-. The postfix expression for the infix expression a + b X c – d ^ e ^ f is?

A) abc X+ def ^^ –
B) abc X+ de^f^ –
C) ab+c Xd – e ^f^
D) -+aXbc^ ^def

Explanation: Given Infix Expression is a + b X c – d ^ e ^ f.
(a b c X +) (d ^ e ^ f). ‘–‘ is present in stack.
(a b c X + d e ^ f ^ -). Thus the final expression is (a b c X + d e ^ f ^ -).

24. If the elements “A”, “B”, “C” and “D” are placed in a stack and
are deleted one at a time, what is the order of removal?

A) ABCD
B) DCBA
C) DCAB
D) ABDC

Explanation: LIFO is followed by the stack (Last In First Out). As a consequence, the element removal order is DCBA.

25. The result of evaluating the postfix expression 5, 4, 6, +, *,
4, 9, 3, /, +, * is?

A) 600
B) 350
C) 650
D) 588

Explanation: The postfix expression is evaluated using stack. We will get the
infix expression as
(5*(4+6))*(4+9/3). On solving the Infix Expression, we get
(5*(10))*(4+3)
= 50*7
= 350.

26. Convert the following infix expressions into its equivalent
postfix expressions.

(A + B D)/(E – F)+G
A) (A B D + E F – / G +)
B) (A B D + E F – / G +)
C) (A B D + E F/- G +)
D) (A B D E F + / – G +)

Explanation: The given infix expression is (A + B D)/(E –
F)+G.
(A B D ^ + ) / (E – F) +G
(A B D ^ + E F – ) + G. ‘/’ is present in stack.
A B D ^ + E F – / G +. Thus Postfix Expression is A B D ^ + E F – / G +.

27. Convert the following Infix expression to Postfix form using a
stack.

x + y * z + (p * q + r) * s, Follow usual precedence rule and
assume that the expression is legal.
a) xyz*+pq*r+s*+
b) xyz*+pq*r+s+*
c) xyz+*pq*r+s*+
d) xyzp+**qr+s*+

Explanation: The Infix Expression is x + y * z + (p * q + r) * s.
(x y z ) + (p * q + r) * s. ‘+’, ‘*’ are present in stack.
(x y z * + p q * r) * s. ‘+’ is present in stack.
x y z * + p q * r + s * +. Thus Postfix Expression is x y z * + p q * r + s *
+.

28. Which of the following statement(s) about stack data structure
is/are NOT correct?

A) Linked List are used for implementing Stacks
B) Top of the Stack always contain the new node
C) Stack is the
FIFO data structure

D) Null link is present in the last node at the bottom of the stack

Explanation: Stack follows LIFO.

29. Consider the following operation performed on a stack of size 5.

Push(1);
Pop(); Push(2); Push(3); Pop(); Push(4); Pop(); Pop(); Push(5);

After
the completion of all operation, the number of elements present in stack is?

a) 1
b) 2
c) 3
d) 4

Explanation: The difference between the number of push and pop operations determines the number of elements in the stack. 5-4=1 is the number of elements.

A stack is a data structure that
uses the last-in, first-out (LIFO) principle. Push and pop are the two basic
operations provided by a stack. Size (the number of data elements currently on
the stack) and peek are two additional operations provided by some layers (look
at the top element without removing it). An Abstract Data Type (ADT) is a data
type that is used in almost all programming languages. It’s called stack
because it looks like a real-life stack, such as a deck of cards or a stack of
plates.  We can only position or remove a card or plate from the top of
the stack, for example.

 

Leave a Reply

Your email address will not be published. Required fields are marked *