Stack Basics: 22 MCQs with answers

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

Warm-up · 13 questions

Q1. What is the fundamental principle followed by a stack data structure?

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

Last In, First Out (LIFO)

A stack follows LIFO: the last element pushed is the first to be popped.

Q2. In an array-based stack, which end is used as the top of the stack?

Beginner
A The first index (0) B The middle index C Any index, depending on the push order D The last used index (top)
Show answer & explanation

The last used index (top)

The top pointer indicates the index of the most recently added element; push/pop operate at that end.

Q3. What does the 'top' variable in an array-based stack represent?

Beginner
A The index of the last element pushed B The address of the stack in memory C The total capacity of the stack D The number of elements in the stack
Show answer & explanation

The index of the last element pushed

The top variable stores the index of the most recent element; it is updated on push/pop.

Q4. What is the time complexity of the push operation in an array-based stack (without resizing)?

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

O(1)

Push only updates the top index and places the element, so it takes constant time.

Q5. What condition indicates that an array-based stack is empty?

Beginner
A top == -1 B top == capacity C top == capacity - 1 D top == 0
Show answer & explanation

top == -1

Initially top is set to -1; when no elements are present, top remains -1.

Q6. In an array-based stack, what does the pop operation do?

Beginner
A Removes the element at the bottom B Increments top and adds a new element C Returns the top element without removing it D Removes the element at the top and decrements top
Show answer & explanation

Removes the element at the top and decrements top

Pop removes the top element and decrements the top index; the element is logically removed.

Q7. Which operation returns the top element without removing it?

Beginner
A push B isEmpty C pop D peek (or top)
Show answer & explanation

peek (or top)

Peek (or top) retrieves the top element while leaving the stack unchanged.

Q8. What is the time complexity of the peek operation in an array-based stack?

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

O(1)

Peek directly accesses the element at the top index, so it is constant time.

Q9. In an array-based stack, what is the initial value of the top pointer?

Beginner
A 1 B capacity - 1 C 0 D -1
Show answer & explanation

-1

Top is initialized to -1 to indicate an empty stack; the first push increments it to 0.

Q10. In an array-based stack, the pop operation removes the element at the top of the stack.

Beginner
A True B False
Show answer & explanation

True

Pop always removes the most recently added element, which is at the top.

Q11. The peek operation in a stack removes the top element from the stack.

Beginner
A True B False
Show answer & explanation

False

Peek only returns the top element without modifying the stack; it does not remove it.

Q12. In an array-based stack, what is the sequence of steps to perform a push operation? Include the overflow check.

Beginner
Show answer & explanation

—

This tests the basic understanding of the push operation's order: checking capacity before modifying the top index and placing the element.

Q13. Describe a real-world application of a stack and explain how the LIFO principle is used in that application.

Beginner
Show answer & explanation

—

This tests the ability to connect the abstract concept of a stack to a practical use case.

Building up · 8 questions

Q14. What happens if you try to push onto a full array-based stack?

Intermediate
A The stack automatically resizes B The oldest element is removed C The element is added at index 0 D An overflow condition occurs
Show answer & explanation

An overflow condition occurs

Without dynamic resizing, pushing to a full stack causes overflow; this is a limitation of fixed-size arrays.

Q15. Which of the following is a common limitation of a fixed-size array-based stack?

Intermediate
A It cannot handle dynamic resizing B It requires O(n) time for push C It does not support LIFO order D It uses more memory than a linked-list stack
Show answer & explanation

It cannot handle dynamic resizing

A fixed-size array cannot grow, so it may overflow; dynamic resizing is needed to overcome this.

Q16. What is the result of the expression: push(5), push(10), pop(), peek()?

Intermediate
A null B 5 C 10 D Error
Show answer & explanation

5

After pushing 5 and 10, pop removes 10, leaving 5 at the top, so peek returns 5.

Q17. Which of the following applications uses a stack?

Intermediate
A Sorting a list of numbers B Maintaining a queue of print jobs C Undo operation in text editors D CPU scheduling
Show answer & explanation

Undo operation in text editors

Undo operations use a stack to reverse actions in LIFO order; CPU scheduling typically uses queues.

Q18. What is the main advantage of an array-based stack over a linked-list stack?

Intermediate
A No need for a top pointer B Unlimited size C Better cache locality and faster access D Simpler to implement dynamic resizing
Show answer & explanation

Better cache locality and faster access

Arrays provide contiguous memory, leading to better cache performance; linked lists use extra memory for pointers.

Q19. Given an array-based stack with capacity 5, initially empty. Perform the following operations and show the final state of the stack (elements from bottom to top) and the value of `top`: push(3), push(7), pop(), push(9), push(2), pop(), peek().

Intermediate
Show answer & explanation

—

This requires applying the operations step-by-step, tracking the top index and the array contents, and understanding that peek does not modify the stack.

Q20. Explain why the time complexity of all stack operations (push, pop, peek, isEmpty) is O(1) in an array-based implementation.

Intermediate
Show answer & explanation

—

This checks the understanding of constant-time operations and why array-based stacks are efficient.

Q21. What are the consequences of not checking for stack overflow before a push and stack underflow before a pop in an array-based stack? Provide a specific example of each.

Intermediate
Show answer & explanation

—

This emphasizes the importance of boundary checks and the typical errors that occur when they are omitted.

Topper level · 1 questions

Q22. Analyze the trade-offs between an array-based stack and a linked-list stack in terms of memory usage, performance, and flexibility. Under what conditions would you prefer the array-based version?

Advanced
Show answer & explanation

—

This requires a deeper understanding of the trade-offs and the ability to justify the choice based on constraints.

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