Q.1 Which of the following operations is not supported by a stack?
Push
Pop
Peek
Enqueue
Explanation - Stack supports Push, Pop, and Peek operations. Enqueue is used in queues.
Correct answer is: Enqueue
Q.2 What is the time complexity of push and pop operations in a stack implemented using an array?
O(1)
O(n)
O(log n)
O(n^2)
Explanation - Push and Pop operations in an array-based stack are performed at the top, taking constant time O(1).
Correct answer is: O(1)
Q.3 Which data structure uses FIFO (First In First Out) principle?
Stack
Queue
Tree
Graph
Explanation - Queue follows FIFO order, meaning the first element added is the first to be removed.
Correct answer is: Queue
Q.4 Which of the following is a common application of a stack?
Undo feature in text editors
Job scheduling
Breadth-first traversal
Database indexing
Explanation - Stacks are used to store operations in reverse order, which allows undo functionality.
Correct answer is: Undo feature in text editors
Q.5 What happens if you try to pop an element from an empty stack?
Overflow
Underflow
Segmentation fault
No effect
Explanation - Stack underflow occurs when pop is attempted on an empty stack.
Correct answer is: Underflow
Q.6 Which of these is not a type of queue?
Circular Queue
Priority Queue
Double-ended Queue
Random Queue
Explanation - Random Queue is not a standard queue type. Standard types include Circular, Priority, and Deque.
Correct answer is: Random Queue
Q.7 In a circular queue, how is the next position after the last element determined?
Increment index by 1
Decrement index by 1
Use modulo operation
Double the index
Explanation - Circular queues wrap around using modulo arithmetic to reuse array positions.
Correct answer is: Use modulo operation
Q.8 Which of the following problems is efficiently solved using stacks?
Expression evaluation
Binary search
Hashing
Graph coloring
Explanation - Stacks are used to evaluate expressions, especially with parentheses and operator precedence.
Correct answer is: Expression evaluation
Q.9 Which of these queue implementations allows insertion and deletion at both ends?
Simple Queue
Circular Queue
Deque
Priority Queue
Explanation - A Deque (Double-ended Queue) allows insertions and deletions at both front and rear.
Correct answer is: Deque
Q.10 What is the time complexity of inserting an element in a queue implemented using a linked list?
O(1)
O(n)
O(log n)
O(n^2)
Explanation - In a linked list implementation, insertion at the rear of a queue is done in constant time.
Correct answer is: O(1)
Q.11 Which of the following is true for a stack?
FIFO
LIFO
Both FIFO and LIFO
None of the above
Explanation - Stack follows Last In First Out (LIFO) principle.
Correct answer is: LIFO
Q.12 Which operation is used to view the top element of a stack without removing it?
Push
Pop
Peek
Enqueue
Explanation - Peek (or Top) operation returns the top element without removing it from the stack.
Correct answer is: Peek
Q.13 Which of the following is a drawback of an array-based stack?
Fixed size
Dynamic size
Fast access
Simple implementation
Explanation - Array-based stacks have a fixed size, which can lead to overflow if the size limit is reached.
Correct answer is: Fixed size
Q.14 In which scenario is a priority queue useful?
Job scheduling
Undo feature
Expression evaluation
Balanced search tree
Explanation - Priority queues are used where elements with higher priority must be processed first, like job scheduling.
Correct answer is: Job scheduling
Q.15 Which of the following is true about a circular queue?
It wastes space
It avoids overflow if managed properly
Insertion is slow
Deletion is not allowed
Explanation - Circular queues efficiently use space and can avoid overflow by wrapping around.
Correct answer is: It avoids overflow if managed properly
Q.16 What will be the output of the following stack operations: push(1), push(2), pop(), push(3), pop()?
1
2
3
None
Explanation - Stack operations: push 1 -> stack=[1]; push 2 -> stack=[1,2]; pop -> removes 2; push 3 -> stack=[1,3]; pop -> removes 3.
Correct answer is: 3
Q.17 Which of the following is a real-life example of a queue?
Undo button in software
Call center waiting line
Browser back button
Stack of plates
Explanation - Call center waiting lines process customers in FIFO order, like a queue.
Correct answer is: Call center waiting line
Q.18 Which of the following is not a characteristic of a queue?
FIFO order
Dynamic size
Random access
Insertion at rear
Explanation - Queues do not allow random access; elements are accessed in FIFO order.
Correct answer is: Random access
Q.19 Which of the following correctly represents the sequence of operations for a stack after push(5), push(10), pop(), push(7)?
[5,10]
[10,7]
[5,7]
[7,10]
Explanation - Stack sequence: push 5 -> [5]; push 10 -> [5,10]; pop -> removes 10; push 7 -> [5,7].
Correct answer is: [5,7]
Q.20 Which queue implementation is suitable when the size of the queue is unknown and may vary dynamically?
Array-based queue
Circular queue
Linked list-based queue
Static queue
Explanation - Linked list-based queues can grow or shrink dynamically as needed.
Correct answer is: Linked list-based queue
Q.21 Which of the following operations can cause overflow in a queue?
Enqueue
Dequeue
Peek
Pop
Explanation - Overflow occurs when trying to insert (enqueue) into a full queue.
Correct answer is: Enqueue
Q.22 Which of the following applications typically use stacks?
Expression conversion from infix to postfix
Breadth-first traversal of a graph
Priority-based task scheduling
CPU scheduling using Round Robin
Explanation - Stacks are used to hold operators and operands during infix-to-postfix conversion.
Correct answer is: Expression conversion from infix to postfix
Q.23 Which of the following is the correct way to check if a stack is empty?
top == null
size == 0
head == null
rear == null
Explanation - Checking if the stack size is zero determines whether the stack is empty.
Correct answer is: size == 0
Q.24 What is the main advantage of using a linked list to implement a stack over an array?
Dynamic size
Faster access
Less memory usage
Easier indexing
Explanation - Linked lists allow stacks to grow and shrink dynamically without a predefined size limit.
Correct answer is: Dynamic size
