NEW
Font size
WorksheetsStacks and Queues Worksheet
Total questions: 43
Worksheet time: 22mins
Which property defines the primary difference between a Stack and a Queue?
The time complexity of insertion
The order of element removal (LIFO vs FIFO)
The ability to store primitive data types
The underlying memory allocation method
In a Circular Queue implemented with an array of size n, what is the condition for the queue being full?
rear == n - 1
front == rear
(rear + 1) % n == front
front + rear == n
What is the result of converting the infix expression (A + B) * C to postfix notation?
* + A B C
A B + C *
A B C + *
A B + * C
Which of the following is an application of a Monotonic Stack?
Finding the Next Greater Element
Implementing a recursive function
Scheduling tasks in an OS
Level-order traversal of a tree
If you implement a Queue using two Stacks, what is the amortized time complexity of the Dequeue operation?
O(n)
O(logn)
O(n2)
O(1)
A 'Deque' (Double-Ended Queue) can be used to implement which of the following?
Only a Stack
Only a Queue
Both a Stack and a Queue
Only a Priority Queue
When evaluating a postfix expression using a stack, what is the correct action when an operator is encountered?
Push the operator onto the stack
Pop two operands, apply the operator, and push the result back
Pop one operand and push the operator
Clear the stack and restart
In the 'Two Stacks in one Array' implementation, where do the stacks typically start to maximize space efficiency?
Both at index 0, growing in the same direction
One at index 0, the other at index n/2
At opposite ends of the array, growing towards the middle
At the middle, growing towards the ends
What happens if you attempt a 'Peek' operation on an empty Stack?
Overflow error
Underflow error or null return
The program crashes automatically
It returns the last deleted value
Which scheduling algorithm in Operating Systems is a direct application of a Queue?
First-Come, First-Served (FCFS)
Shortest Job First
Priority Scheduling
Last-In, First-Out Scheduling
In a linked list implementation of a Stack, why is it better to push at the head rather than the tail?
It uses less memory
It ensures O(1) time for both push and pop
Linked lists cannot have a tail pointer
It prevents stack overflow
Which data structure is required to implement Depth First Search (DFS) on a graph non-recursively?
Queue
Stack
Priority Queue
Hash Map
What is the primary disadvantage of a linear Queue implemented with a static array?
Insertion is O(n)
Space is wasted after several dequeue operations
It cannot store integers
Deletion is O(n)
Which structure is best suited for implementing a 'Back' button in a web browser?
Queue
Circular Queue
Stack
Binary Search Tree
How many stacks are typically needed to simulate a Priority Queue logic?
One
Two (with sorting during push or pop)
Zero
Four
What is the time complexity to retrieve the 'Minimum' element in a specifically designed 'Min Stack'?
O(n)
O(logn)
O(1)
O(1) amortized
In a Queue, the operation 'Front' or 'Peek' returns:
The oldest element without removing it
The newest element without removing it
The oldest element and removes it
The middle element
What is the postfix form of A + B * C?
A B + C *
A B C * +
+ A * B C
A B * C +
Which data structure is typically used to manage 'undo' operations in a text editor?
Queue
Hash Table
Stack
Graph
What is the time complexity of reversing a Queue using an auxiliary Stack?
O(n2)
O(n)
O(1)
O(logn)
A 'Priority Queue' can be used to efficiently implement which of the following?
Dijkstra's Algorithm
Expression Evaluation
String Reversal
Balanced Parentheses
In a Deque, which operations are available that are NOT in a standard Queue?
Peek and Enqueue
IsFull and IsEmpty
Insertion and deletion at both the front and rear
Random access by index
What is the max number of elements a stack can hold if array size is N and the top pointer starts at −1 ?
N−1
N
N+1
Infinite
Which of these is NOT a real-world example of a Queue?
Cars at a toll booth
People waiting for an elevator
A stack of books on a desk
Printer tasks in a spooler
If you push 10, 20, 30 onto a stack and then pop twice, what is the next value returned by a 'Peek'?
20
30
10
None
In the linked list implementation of a Queue, where should 'front' and 'rear' be?
Front at the head, Rear at the tail
Front at the tail, Rear at the head
Both at the head
Both at the tail
What is the prefix form of the expression A+B ?
A B +
+ A B
A + B
B A +
Which of these is a valid implementation of a Stack using only one Queue?
It is impossible with only one queue
Enqueue the element and then rotate the queue n−1 times
Simply use 'Dequeue' for 'Pop'
Sort the queue after every insertion
What is 'Stack Overflow'?
An error when pushing onto a full stack
An error when popping from an empty stack
When a stack is converted to a queue
When the stack memory is cleared
Which data structure is most helpful in solving the 'Sliding Window Maximum' problem?
Stack
Deque
Simple Queue
Binary Search Tree
How do you check if a Stack with top initialized to -1 is empty?
top == 0
top == N
top == -1
top == null
In a Priority Queue, if two elements have the same priority, they are typically handled:
By serving the most recent one first
In FIFO order
By discarding one
By throwing an error
Which of these is used to implement a 'Call Stack' in programming?
Stack
Queue
Priority Queue
Linked List
Which data structure is most appropriate for a system handling print jobs?
Stack
Monotonic Stack
Queue
Binary Search Tree
In an array-based implementation of a Stack where the top pointer is initialized to -1, which code correctly implements the push operation?
stack[top++] = x;
stack[++top] = x;
stack[top] = x; top++;
top = top + 1; x = stack[top];
In a Circular Queue of capacity N, which line of code correctly updates the rear index during an enqueue operation?
rear = rear + 1;
rear = (rear % N) + 1;
rear = (rear + 1) % N;
rear = N % (rear + 1);
Which code segment correctly checks if a Circular Queue is FULL?
return (rear + 1) % size == front;
return front == rear + 1;
return rear == size - 1;
return front == 0 && rear == size;
What is the output of the following Python code? Python stack = [10, 20, 30] stack.append(40) stack.pop() stack.pop() print(stack[-1])
10
20
30
40
Python from collections import deque q = deque([1, 2, 3]) q.append(4) q.popleft() q.append(q.popleft()) print(list(q)) What will be the state of the queue q after this execution?
[3, 4, 2]
[1, 2, 3, 4]
[2, 3, 4]
[4, 1, 2]
To evaluate a Postfix expression, what logic completes the following snippet? Python # op2 is the first popped value, op1 is the second if token == '-': stack.append(__________)
op2 - op1
abs(op1 - op2)
op1 - op2
-(op1 + op2)
When implementing a Stack using a Singly Linked List, why is it better to push/pop at the head?
It allows O(1) time for both operations.
It uses less memory than pushing at the tail.
It prevents the stack from overflowing.
Pushing at the tail requires a Doubly Linked List.
In a "Queue using two Stacks" model, if stack2 (the dequeue stack) is empty, what is the required code logic?
Return "Underflow".
Move all elements from Stack1 to Stack2 and then pop from Stack2.
Pop the bottom-most element from Stack1.
Wait for more elements to be enqueued.
What is the time complexity of retrieving the minimum element from a properly implemented MinStack?
O(n)
O(logn)
O(1)
O(n2)
