Stack: 19 MCQs with answers

All 19 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 9 questions

Q1. Which principle does a stack follow?

Beginner
A Last In, First Out (LIFO) B Priority Order C Random Access D First In, First Out (FIFO)
Show answer & explanation

Last In, First Out (LIFO)

A stack is a LIFO data structure, meaning the last element added is the first to be removed.

Q2. Which operation adds an element to the top of a stack?

Beginner
A peek B pop C push D enqueue
Show answer & explanation

push

The push operation inserts an element onto the top of the stack.

Q3. Which operation removes the top element from a stack?

Beginner
A pop B peek C dequeue D push
Show answer & explanation

pop

The pop operation removes and returns the top element of the stack.

Q4. What does the 'peek' operation do on a stack?

Beginner
A Adds an element to the bottom B Checks if the stack is empty C Returns the top element without removing it D Removes the top element
Show answer & explanation

Returns the top element without removing it

Peek (or top) returns the top element without modifying the stack.

Q5. If you push elements 1, 2, 3 onto a stack in that order, what will be the first element popped?

Beginner
A None B 3 C 1 D 2
Show answer & explanation

3

Due to LIFO, the last pushed element (3) is popped first.

Q6. Which of the following is NOT a typical stack operation?

Beginner
A push B pop C peek D enqueue
Show answer & explanation

enqueue

Enqueue is a queue operation, not a stack operation.

Q7. Which of the following is a real-world analogy for a stack?

Beginner
A A playlist in shuffle mode B A stack of plates C A round-robin tournament D A line of people waiting for a bus
Show answer & explanation

A stack of plates

A stack of plates is a classic analogy: you add and remove plates from the top.

Q8. A stack is a FIFO data structure.

Beginner
A True B False
Show answer & explanation

False

A stack is LIFO (Last In, First Out), not FIFO.

Q9. The 'peek' operation removes the top element from the stack.

Beginner
A True B False
Show answer & explanation

False

Peek returns the top element without removing it; pop removes it.

Building up · 9 questions

Q10. Which of the following is a common application of a stack?

Intermediate
A Round-robin scheduling B Undo/Redo in text editors C Breadth-first search D CPU scheduling
Show answer & explanation

Undo/Redo in text editors

Stacks are used to implement undo/redo features, as they naturally store actions in LIFO order.

Q11. Which data structure is used to implement function calls in most programming languages?

Intermediate
A Linked list B Stack C Tree D Queue
Show answer & explanation

Stack

The call stack is a stack data structure that manages function calls and returns.

Q12. What is the time complexity of push and pop operations on a stack implemented with an array?

Intermediate
A O(n) B O(log n) C O(n^2) D O(1)
Show answer & explanation

O(1)

Array-based stack operations (push/pop) operate at the end of the array, which is O(1) on average.

Q13. In the expression '2 3 +', which notation is used?

Intermediate
A Reverse Polish B Postfix C Prefix D Infix
Show answer & explanation

Postfix

Postfix notation places operators after operands; stacks are used to evaluate postfix expressions.

Q14. What is the result of evaluating the postfix expression '5 3 + 2 *'?

Intermediate
A 10 B 16 C 13 D 8
Show answer & explanation

16

Push 5, push 3, pop 5 and 3, add to get 8, push 8, push 2, pop 8 and 2, multiply to get 16.

Q15. Which of the following problems is commonly solved using a stack?

Intermediate
A Balanced parentheses checking B Finding the shortest path C Hashing D Sorting a list
Show answer & explanation

Balanced parentheses checking

Stacks are used to check balanced parentheses by pushing opening brackets and popping on closing brackets.

Q16. What happens if you pop from an empty stack?

Intermediate
A It throws an underflow error B It returns 0 C It returns null D It creates a new element
Show answer & explanation

It throws an underflow error

Popping from an empty stack is an underflow condition, typically resulting in an error or exception.

Q17. What is the space complexity of a stack with n elements?

Intermediate
A O(n^2) B O(n) C O(log n) D O(1)
Show answer & explanation

O(n)

A stack storing n elements requires O(n) space.

Q18. Which of the following is NOT a typical use of a stack?

Intermediate
A Function call management B Depth-first search C Breadth-first search D Expression evaluation
Show answer & explanation

Breadth-first search

Breadth-first search uses a queue, not a stack.

Topper level · 1 questions

Q19. Which of the following is a common application of stacks in compilers?

Advanced
A Code optimization B Memory allocation C Garbage collection D Syntax analysis
Show answer & explanation

Syntax analysis

Stacks are used in syntax analysis (parsing) to track nested structures and operators.

Make your own

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