Chapter Stack – Class Test Marks : 20
SECTION – A 6X1=6
1. The best data structure to check whether an arithmetic expression has
balanced parenthesis is a
a) Stack b) Queue c) Tree d) List
2. 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
a) 2,2,1,1,2 b) 2,2,1,2,2 c) 2,1,2,2,1 d) 2,1,2,2,2
3. Which one of the following is an application of Stack Data Structure?
a) Managing function calls
b)The stock span problem
c)Arithmetic expression evaluation
d)All of the above
4. Consider the following sequence of operations on an empty stack.
Push(54);push(52);pop();push(55);push(62);s=pop();
What is the value of s?
5. Convert the following infix expression into its equivalent post fix expression
(A + B^ D) / (E – F) + G
a) ABD^ + EF / – G+ b) ABD + ^EF – / G+
b) c) ABD + ^EF / – G+ d) ABD^ + EF – / G+
6. Which of the following is not an inherent application of stack?
a) Implementation of recursion
b) Evaluation of a postfix expression
c) Job scheduling
d) Reverse a string
SECTION – B 2X2=4
[Link] stack overflow and underflow conditions and explain how they can be
handled in a Python implementation.
8. Explain the Last-In-First-Out (LIFO) principle with a suitable analogy.
SECTION – C 4 X 3 = 12
9. Write a menu-driven program in Python to perform Push, Pop, Peek (display top
element), and Display (all elements) operations on a stack. Handle stack overflow
and underflow conditions.
10. Write a program that takes a list of numbers or strings and pushes only specific
elements onto a stack based on a given condition (e.g., only even numbers, only
words without vowels, only numbers divisible by 3 or 5).
11 The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
12. Write a function in python,push(book) where, book is a dictionary containing
the details of a book in form of {bookno:price}.
The function should push the book in the stack which have price greater than
[Link] display the count of elements pushed into the stack and name of the
book.
ANSWER KEY
1. A) stack
2. A) 2,2,1,1,2
3. D) all of the above
4. 62
5. D) d) ABD^ + EF – / G+
6. C) Job Scheduling
7. Stack overflow - check length of the list
Stack underflow – check the list is empty
8. Stack of plates
shuttleCock tubes
11. AB + CD * E - * F * G /