Stack Basics: 17 MCQs with answers
All 17 multiple-choice questions from this kit, free and with no sign-up.
Warm-up · 10 questions
Q1. What does LIFO stand for in the context of a stack?
BeginnerShow answer & explanation
Last In, First Out
LIFO means the last element added to the stack is the first one removed.
Q2. Which operation adds an element to the top of a stack?
BeginnerShow answer & explanation
push
Push is the operation that inserts an element onto the top of the stack.
Q3. Which operation removes the top element from a stack?
BeginnerShow answer & explanation
pop
Pop removes the element that is currently at the top of the stack.
Q4. What does the 'peek' operation do on a stack?
BeginnerShow answer & explanation
Returns the top element without removing it
Peek (or top) returns the value of the top element but does not remove it from the stack.
Q5. If you push elements 1, 2, 3 onto a stack in that order, what will be the first element popped?
BeginnerShow answer & explanation
3
The last pushed element is 3, and due to LIFO, it is popped first.
Q6. What happens if you try to pop from an empty stack?
BeginnerShow answer & explanation
It throws an exception (stack underflow)
Popping from an empty stack causes an underflow error, often an exception in programming.
Q7. Which of the following is NOT a valid stack operation?
BeginnerShow answer & explanation
enqueue
Enqueue is a queue operation, not a stack operation.
Q8. In a stack, where does the 'top' pointer point?
BeginnerShow answer & explanation
The last inserted element
The top pointer always points to the most recently inserted element, which is the one that will be popped next.
Q9. A stack follows the FIFO (First In, First Out) principle.
BeginnerShow answer & explanation
False
A stack follows LIFO (Last In, First Out), not FIFO.
Q10. The 'pop' operation removes the top element from the stack.
BeginnerShow answer & explanation
True
Pop removes the element that is currently at the top of the stack.
Building up · 7 questions
Q11. Which of the following is a common application of a stack?
IntermediateShow answer & explanation
Function call management in recursion
Stacks are used to manage function calls in recursion, as each call is pushed and popped in LIFO order.
Q12. In the context of expression evaluation, what is a stack used for?
IntermediateShow answer & explanation
Converting infix to postfix
Stacks are used in expression conversion and evaluation, such as converting infix notation to postfix.
Q13. What is the time complexity of push and pop operations on a stack implemented with an array?
IntermediateShow answer & explanation
O(1)
Array-based stack operations (push and pop) only access the top element, so they run in constant time O(1).
Q14. Which of the following problems is typically solved using a stack?
IntermediateShow answer & explanation
Checking balanced parentheses
Stacks are used to check balanced parentheses by pushing opening brackets and popping on closing brackets.
Q15. Which data structure is used to implement the undo feature in text editors?
IntermediateShow answer & explanation
Stack
Undo operations are stored in a stack; the most recent action is undone first (LIFO).
Q16. What is the output of the following sequence? push(5), push(10), pop(), push(15), pop()
IntermediateShow answer & explanation
15
After pushing 5 and 10, pop removes 10. Then push 15, and pop removes 15, so the last popped value is 15.
Q17. Which of the following is a real-world example of a stack?
IntermediateShow answer & explanation
A stack of plates in a cafeteria
A stack of plates is LIFO: you take the top plate first, which is the last one placed.
Your notes can be a kit like these
Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.
- Chapter notes
- Flashcards
- Practice MCQs
- Scored tests
- Exam prep
Get Veda free See what students get
Free to start · No ads · Works in 42 languages