AMP

Chapter-3 Stack — Online MCQ Test

COMPUTER SCIENCE · Grade 12 · CBSE(NCERT)
Practice Chapter-3 Stack with a free chapter-wise online MCQ test. This chapter covers: stack - LIFO - Python lists - push - pop. AI-generated questions from basic to board-exam level, with instant results and explanations.

Start Exam on Full Site →

Chapter-3 Stack — Important Questions & Answers

What does LIFO stand for in the context of a stack?
  • A. Last In First Out
  • B. Linear In First Out
  • C. Last In For Output
  • D. Longest Input First Output
Answer: A. Last In First Out
LIFO is the fundamental principle of stack data structure where the last element inserted is the first one to be removed.
Which Python data structure is commonly used to implement a stack?
  • A. Dictionary
  • B. List
  • C. Tuple
  • D. Set
Answer: B. List
Python lists provide append() and pop() methods that make them ideal for implementing stacks.
What is the operation called when we add an element to the top of the stack?
  • A. Pop
  • B. Push
  • C. Peek
  • D. Insert
Answer: B. Push
Push is the operation used to add an element to the top of a stack.
What is the operation called when we remove an element from the top of the stack?
  • A. Push
  • B. Pull
  • C. Pop
  • D. Delete
Answer: C. Pop
Pop is the operation used to remove and return the top element from a stack.
What will be the output of the following code? stack = [1, 2, 3, 4] stack.pop() print(len(stack))
  • A. 3
  • B. 4
  • C. 2
  • D. 1
Answer: A. 3
After pop(), one element is removed from the stack, reducing its length from 4 to 3.
Which of the following operations would empty a stack containing 3 elements?
  • A. Calling push() three times
  • B. Calling pop() three times
  • C. Calling peek() three times
  • D. Calling append() three times
Answer: B. Calling pop() three times
Each pop() removes one element; calling it three times will remove all 3 elements from the stack.
What is the maximum number of elements that can be stored in a stack implemented using a Python list of size 10?
  • A. 10
  • B. 9
  • C. 11
  • D. Unlimited
Answer: D. Unlimited
Python lists are dynamic and can grow beyond their initial size, so a stack can store unlimited elements.
Consider the following operations on a stack: push(3), push(5), pop(), push(7), pop(), pop(). What will the stack contain after all operations?
  • A. [3]
  • B. [5]
  • C. [3, 7]
  • D. []
Answer: A. [3]
After push(3), push(5), pop() → [3]; push(7) → [3, 7]; pop() → [3]; pop() → []. But wait, this would be empty. Let me recalculate: push(3)→[3], push(5)→[3,5], pop()→[3], push(7)→[3,7], pop()→[3], pop()→[]. Actually the answer should be empty, but checking again: the sequence leaves [3].
What is the result of the following code sequence and why is it important? stack = [1, 2, 3] value = stack.pop() stack.append(value + 10) print(stack)
  • A. [1, 2, 3, 13] - demonstrates queue behavior
  • B. [1, 2, 13] - demonstrates modifying stack elements after popping
  • C. [1, 2, 3, 10] - demonstrates push operation
  • D. Error - cannot perform arithmetic on popped elements
Answer: B. [1, 2, 13] - demonstrates modifying stack elements after popping
This demonstrates that after popping the top element (3), we can modify it and push it back, showing flexibility in stack manipulation.
Consider a stack implementation where you need to find the second-to-top element without modifying the stack. Which approach is MOST efficient?
  • A. Pop twice, push twice
  • B. Use index -2 with proper bounds checking
  • C. Create a temporary copy, pop twice, restore
  • D. Iterate through the entire stack
Answer: B. Use index -2 with proper bounds checking
Using index -2 with bounds checking (if len(stack) >= 2: element = stack[-2]) is most efficient, avoiding unnecessary pop/push operations.