Stack operations (push, pop, peek) MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is a stack in data structures?

a) A data structure that allows random access
b) A data structure that follows LIFO (Last In, First Out) principle
c) A data structure that allows traversal from both ends
d) A data structure that requires sorting before access
Answer: b) A data structure that follows LIFO (Last In, First Out) principle
Which operation adds an element to the top of the stack?

a) Pop
b) Peek
c) Push
d) Insert
Answer: c) Push
What happens when you pop an element from an empty stack?

a) Stack becomes undefined
b) Stack becomes null
c) An error occurs
d) Nothing happens
Answer: c) An error occurs
What is the time complexity of the push operation in a stack implemented using an array with sufficient capacity?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)
Which operation removes and returns the top element of the stack?

a) Push
b) Pop
c) Peek
d) Remove
Answer: b) Pop
What is the time complexity of the pop operation in a stack implemented using a linked list?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)
Which operation returns the top element of the stack without removing it?

a) Push
b) Pop
c) Peek
d) Top
Answer: c) Peek
What happens when you peek an element from an empty stack?

a) Stack becomes undefined
b) Stack becomes null
c) An error occurs
d) Nothing happens
Answer: c) An error occurs
What is the time complexity of the peek operation in a stack?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)
Which of the following statements is true about stack operations?

a) Push and pop can be performed simultaneously
b) Pop removes the bottom element of the stack
c) Peek changes the stack size
d) Push can be performed only once
Answer: a) Push and pop can be performed simultaneously
Which data structure is commonly used to implement a stack?

a) Queue
b) Array
c) Linked list
d) Tree
Answer: b) Array
In a stack, which operation modifies the size of the stack?

a) Push
b) Pop
c) Peek
d) None of the above
Answer: d) None of the above
What happens if you try to push an element onto a full stack (using an array implementation)?

a) The element is added at the top
b) Stack becomes undefined
c) An error occurs
d) Nothing happens
Answer: c) An error occurs
Which operation is used to check if a stack is empty?

a) isEmpty
b) isFull
c) size
d) length
Answer: a) isEmpty
What is the space complexity of a stack operation?

a) O(1)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: a) O(1)
Which of the following statements is true about the stack data structure?

a) It allows elements to be accessed randomly
b) It follows FIFO (First In, First Out) principle
c) It is used for breadth-first search algorithms
d) It is used for depth-first search algorithms
Answer: d) It is used for depth-first search algorithms
What is the primary limitation of using an array to implement a stack?

a) Limited capacity
b) Slow access time
c) Inefficient insertion and deletion
d) Inability to perform push operation
Answer: a) Limited capacity
Which stack operation is responsible for decreasing the size of the stack?

a) Push
b) Pop
c) Peek
d) None of the above
Answer: b) Pop
Which stack operation can be used to reverse the order of elements?

a) Push
b) Pop
c) Peek
d) None of the above
Answer: d) None of the above
In stack operations, what does the term “top” refer to?

a) The element at the bottom of the stack
b) The size of the stack
c) The element at the top of the stack
d) The middle element of the stack
Answer: c) The element at the top of the stack

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs