0% found this document useful (0 votes)
1 views6 pages

Chapter 03 Stack

This document contains multiple-choice questions and fill-in-the-blank exercises related to the stack data structure, covering concepts such as LIFO principle, stack operations, and Python implementation. It includes questions on postfix notation, infix expressions, and assertions about stack properties. The answers to the questions are also provided, serving as a study guide for understanding stacks in programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

Chapter 03 Stack

This document contains multiple-choice questions and fill-in-the-blank exercises related to the stack data structure, covering concepts such as LIFO principle, stack operations, and Python implementation. It includes questions on postfix notation, infix expressions, and assertions about stack properties. The answers to the questions are also provided, serving as a study guide for understanding stacks in programming.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter – 03

STACK
MULTIPLE CHOICE QUESTIONS (MCQs)

1. What is the principle followed by a Stack?


A. FIFO
B. LILO
C. IFO
D. FILO
Answer: C. LIFO

2. In Python, which data type is commonly used to implement a stack?


A. Tuple
B. Set
C. List
D. Dictionary
Answer: C. List

3. What will happen if a POP operation is performed on an empty stack?


A. Overflow
B. Underflow
C. Top Element Removed
D. Nothing Happens

Answer: B. Underflow

4. Which of the following is NOT a real-life example of a stack?


A. Bangles worn on wrist
B. Queue at a movie theatre
C. Pile of books
D. Stack of chairs
Answer: B. Queue at a movie theatre

5. Which method in Python list is used to remove the top element in a stack?
A. remove()
B. del()
C. pop()
D. discard()

Answer: C. pop()

6. In infix expressions, where are the operators placed?


A. After operands
B. Before operands
C. Between operands
D. At the end

Answer: C. Between operands

7. What is postfix notation also known as?


A. Forward Polish
B. Prefix
C. Infix
D. Reverse Polish

Answer: D. Reverse Polish


8. Which function checks if a stack is empty?
A. isEmpty()
B. emptyStack()
C. checkEmpty()
D. None
Answer: A. isEmpty()

9. What type of error occurs when trying to push an element into a full stack (in languages with fixed stack size)?
A. Syntax Error
B. Runtime Error
C. Overflow
D. Underflow
Answer: C. Overflow

10. What would be the result of evaluating the postfix expression: 7 8 2 * 4 / +?


A. 15
B. 11
C. 14
D. 10
Answer: B. 11

11. Which operator has the highest precedence in arithmetic expressions?


A. +
B. -
C. *
D. =
Answer: C. *

12. In the conversion of infix to postfix, where are the operators stored during processing?
A. Queue
B. List
C. Stack
D. Array
Answer: C. Stack

13. Which function is used to read the topmost element from the stack?
A. pop()
B. top()
C. peek()
D. get()

Answer: B. top()

14. What is the output of the top() function when the stack is empty?
A. 0
B. error
C. None
D. Null
Answer: C. None

15. What is the postfix equivalent of the infix expression (x + y)/(z * 8)?
A. xy+z8/
B. +xyz8/
C. /+xyz8
D. x+yz/8
Answer: A. xy+z8*/**
16. Which of the following is a valid use of stack in text/image editors?
A. Spell check
B. Redo/Undo
C. Save file
D. Crop image

Answer: B. Redo/Undo

17. Which stack operation returns the number of elements?


A. size()
B. length()
C. count()
D. getSize()

Answer: A. size()

18. During infix to postfix conversion, what happens when a right parenthesis is encountered?
A. It is ignored
B. It is pushed to stack
C. Operators are popped till left parenthesis
D. Nothing happens

Answer: C. Operators are popped till left parenthesis

19. Which one of the following statements is FALSE about stack operations in Python (based on the chapter)?
A. append() is used to push elements
B. pop() removes the topmost element
C. We declare stack size in Python
D. Stack can be implemented using list

Answer: C. We declare stack size in Python

20. What is the postfix expression equivalent of: A * ((C + D) / E)?


A. ACD+E/*
B. AC+DE/
C. ACD+E/
D. AC+D/E*

Answer: A. ACD+E/
21.
Assertion (A): Stack is a linear data structure that follows Last-In-First-Out (LIFO) order.
Reason (R): In a stack, insertion and deletion happen at the same end known as TOP.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: A
22.
Assertion (A): The pop() method in Python list implementation of a stack removes the first element. Reason (R):
In stack implementation, elements are always inserted and removed from the beginning of the list.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: D
23.
Assertion (A): Stack is a useful data structure for reversing a string.
Reason (R): Stack allows deletion of elements from the bottom, enabling reverse traversal.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true

Answer: C

24.
Assertion (A): A stack is used for matching parentheses in expressions.
Reason (R): Stack helps in storing and retrieving nested structures in reverse order.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true

Answer: A

25.
Assertion (A): Overflow condition occurs when an element is inserted into a full stack in Python.
Reason (R): Python lists have a fixed size and cannot grow beyond a limit.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true

Answer: C

26.
Assertion (A): Infix expressions are easy for humans to read but difficult for machines to evaluate.
Reason (R): Infix expressions require knowledge of operator precedence and parentheses handling.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: A
27.
Assertion (A): In postfix notation, parentheses are not required.
Reason (R): Postfix notation places operators in a way that respects operator precedence inherently.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: A
28.
Assertion (A): While converting an infix expression to postfix, operands are pushed onto the stack.
Reason (R): The stack is used to hold operands and not operators.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: C
29.
Assertion (A): In evaluation of postfix expression, operators are pushed onto the stack.
Reason (R): Stack helps evaluate binary operators from left to right.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true
Answer: D

30.
Assertion (A): Stack is a helpful structure in browser history navigation.
Reason (R): The back button uses LIFO mechanism to navigate to the previous pages.
A. Both A and R are true, and R is the correct explanation of A
B. Both A and R are true, but R is not the correct explanation of A
C. A is true, but R is false
D. A is false, but R is true

Answer: A

FILL IN THE BLANKS

1. A ________________ is a linear data structure in which insertion and deletion are done from the same end.

Answer: Stack

2. Stack follows the ________________ principle, where the last element added is the first one removed.

Answer: LIFO (Last-In-First-Out)

3. In Python, a stack can be implemented using the ________________ data type.

Answer: list

4. The operation to insert an element into a stack is called ________________ .

Answer: PUSH

5. The operation to remove the topmost element from a stack is called ________________ .

Answer: POP

6. Attempting to remove an element from an empty stack leads to ________________ condition.

Answer: Underflow

7. In stack implementation using Python list, elements are added using the ________________ method.

Answer: append()

8. The function in stack returns the number of elements present.

Answer: size

9. The ________________ function retrieves the most recently added element without removing it.

Answer: top

10. The postfix expression of (x + y)/(z * 8) is ________________.

Answer: xy+z8*/
11. Infix notation places operators ________________ the operands.

Answer: between

12. Postfix notation is also called ________________ notation.

Answer: Reverse Polish

13. During infix to postfix conversion, only ________________ are pushed onto the stack.

Answer: operators

14. In evaluation of postfix expression, only ________________ are pushed onto the stack.

Answer: operands

15. The isEmpty() function returns ________________ if the stack contains no elements.

Answer: True

You might also like