Stacks MCQs

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

What is a stack?
A) A linear data structure that follows the Last In First Out (LIFO) principle
B) A linear data structure that follows the First In First Out (FIFO) principle
C) A non-linear data structure
D) A type of queue
Answer: A) A linear data structure that follows the Last In First Out (LIFO) principle

What operation adds an element to the top of a stack?
A) Enqueue
B) Dequeue
C) Push
D) Pop
Answer: C) Push

What operation removes the top element from a stack?
A) Enqueue
B) Dequeue
C) Push
D) Pop
Answer: D) Pop

What is the time complexity for the push operation in a stack?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)

What is the time complexity for the pop operation in a stack?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: A) O(1)

What is the main disadvantage of using an array to implement a stack?
A) Fixed size
B) Slow access
C) Complexity in implementation
D) None of the above
Answer: A) Fixed size

Which of the following is true about a stack?
A) Elements can be accessed in any order
B) The last element added is the first to be removed
C) It supports random access
D) It is a non-linear data structure
Answer: B) The last element added is the first to be removed

What is the result of popping from an empty stack?
A) It returns NULL
B) It causes an underflow error
C) It returns zero
D) It returns the top element
Answer: B) It causes an underflow error

What is the main application of stacks in programming?
A) Implementing queues
B) Function call management
C) Sorting data
D) Storing data in arrays
Answer: B) Function call management

Which of the following operations is NOT supported by a stack?
A) Push
B) Pop
C) Peek
D) Dequeue
Answer: D) Dequeue

What does the peek operation do in a stack?
A) Adds an element to the stack
B) Removes the top element from the stack
C) Returns the top element without removing it
D) Clears the stack
Answer: C) Returns the top element without removing it

How is a stack typically represented in memory?
A) Using arrays only
B) Using linked lists only
C) Using both arrays and linked lists
D) Using trees
Answer: C) Using both arrays and linked lists

What happens to the stack pointer when an element is pushed onto the stack?
A) It moves up
B) It moves down
C) It remains unchanged
D) It points to NULL
Answer: A) It moves up

What is the maximum size of a stack implemented using an array?
A) Dynamic, can grow indefinitely
B) Limited by the memory available
C) Fixed at the time of declaration
D) Depends on the programming language
Answer: C) Fixed at the time of declaration

What is the primary use of the stack data structure in recursion?
A) To store global variables
B) To keep track of function calls
C) To sort data
D) To manage memory
Answer: B) To keep track of function calls

What will happen if you try to push an element onto a full stack?
A) The stack will resize
B) It will overwrite the bottom element
C) It causes an overflow error
D) The element will be ignored
Answer: C) It causes an overflow error

Which of the following scenarios can be solved using a stack?
A) Balancing parentheses
B) Reversing a string
C) Depth-first search in graphs
D) All of the above
Answer: D) All of the above

In which data structure do you use a stack to evaluate expressions?
A) Queue
B) Array
C) Linked List
D) Binary Tree
Answer: A) Queue

Which of the following can cause a stack overflow?
A) Using too much memory
B) Too many recursive function calls
C) Pushing elements onto a full stack
D) Both B and C
Answer: D) Both B and C

What is the space complexity of a stack implemented with a linked list?
A) O(1)
B) O(n)
C) O(log n)
D) O(n log n)
Answer: B) O(n)

Which of the following best describes a stack underflow?
A) Adding elements to a full stack
B) Removing elements from an empty stack
C) Trying to access the top element without removing it
D) None of the above
Answer: B) Removing elements from an empty stack

How do you implement a stack using two queues?
A) By using one queue for storing elements and the other for reversing the order
B) By using one queue for pushing and one for popping
C) By interleaving the two queues
D) It cannot be done
Answer: A) By using one queue for storing elements and the other for reversing the order

Which of the following is an application of a stack?
A) Undo functionality in applications
B) Traversing a tree
C) Implementing a binary search
D) All of the above
Answer: A) Undo functionality in applications

What is the output of the following code if the stack is empty? stack.pop();
A) It removes the last element
B) It returns NULL
C) It throws an error
D) It does nothing
Answer: C) It throws an error

What is the purpose of using a stack for parsing expressions?
A) To evaluate expressions
B) To store intermediate values
C) To manage operator precedence
D) All of the above
Answer: D) All of the above

How does a stack implemented with a linked list grow?
A) It grows only when elements are added
B) It can grow and shrink dynamically
C) It has a fixed size
D) It cannot grow
Answer: B) It can grow and shrink dynamically

What is a common way to implement a stack using an array?
A) Using a circular queue
B) By maintaining a top index
C) By using a fixed size
D) Both B and C
Answer: D) Both B and C

Which of the following statements is true about a stack?
A) It allows random access to elements
B) The first element added is the first to be removed
C) It is a last-in-first-out data structure
D) It does not support the peek operation
Answer: C) It is a last-in-first-out data structure

In a stack, what does it mean to “pop” an element?
A) To remove the bottom element
B) To remove the top element
C) To view the top element
D) To add a new element
Answer: B) To remove the top element

Which data structure can be used to implement recursion?
A) Array
B) Stack
C) Queue
D) Tree
Answer: B) Stack

What is the effect of using delete on a stack node in C++?
A) It frees the memory allocated for that node
B) It only removes the data
C) It causes a memory leak
D) It does nothing
Answer: A) It frees the memory allocated for that node

What is the primary characteristic of a stack’s push and pop operations?
A) They are executed in constant time
B) They are executed in linear time
C) They require sorting
D) They require additional memory
Answer: A) They are executed in constant time

What is the main function of the “top” operation in a stack?
A) To add an element
B) To remove an element
C) To view the top element without removing it
D) To check if the stack is empty
Answer: C) To view the top element without removing it

What is the relationship between stack and recursion?
A) Stacks are not used in recursion
B) Each function call in recursion uses a stack frame
C) Recursion cannot be implemented using a stack
D) Both are the same
Answer: B) Each function call in recursion uses a stack frame

Which of the following describes the stack’s memory allocation?
A) Stacks use dynamic memory allocation only
B) Stacks can use both static and dynamic memory allocation
C) Stacks use fixed memory allocation only
D) Stacks do not require memory allocation
Answer: B) Stacks can use both static and dynamic memory allocation

 

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