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?

Beginner
A First In, Last Out B Last In, Last Out C Last In, First Out D First In, First Out
Show 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?

Beginner
A isEmpty B peek C pop D push
Show 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?

Beginner
A peek B pop C push D size
Show 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?

Beginner
A Adds an element to the top B Removes the top element C Returns the top element without removing it D Checks if the stack is empty
Show 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?

Beginner
A 1 B Cannot be determined C 2 D 3
Show 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?

Beginner
A It returns null B It throws an exception (stack underflow) C It does nothing D It returns 0
Show 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?

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

enqueue

Enqueue is a queue operation, not a stack operation.

Q8. In a stack, where does the 'top' pointer point?

Beginner
A The last inserted element B The bottom of the stack C The middle element D The first inserted element
Show 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.

Beginner
A True B False
Show answer & explanation

False

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

Q10. The 'pop' operation removes the top element from the stack.

Beginner
A True B False
Show 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?

Intermediate
A Breadth-first search in a graph B Function call management in recursion C Implementing a priority queue D Scheduling processes in an operating system
Show 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?

Intermediate
A Converting infix to postfix B Sorting numbers C Storing variables D Counting tokens
Show 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?

Intermediate
A O(n) B O(1) C O(log n) D O(n log n)
Show 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?

Intermediate
A Sorting an array B Checking balanced parentheses C Searching a binary search tree D Finding the shortest path in a graph
Show 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?

Intermediate
A Linked list B Tree C Stack D Queue
Show 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()

Intermediate
A Nothing, error B 5 C 10 D 15
Show 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?

Intermediate
A A queue of tasks in a printer B A stack of plates in a cafeteria C A line of people waiting for a bus D A round-robin scheduler
Show 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.

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