Font size
WorksheetsStack and Queue Quiz
Total questions: 168
Worksheet time: 1hrs 29mins
Which of the following data structure works on Last In First Out (LIFO) principle?
Queue
Stack
Array
Linked List
Which operation inserts an element into a stack?
Add
Enqueue
Push
Insert
What is the operation called that removes an element from the top of the stack?
Delete
Remove
Dequeue
Pop
In a stack, where is the new element added?
Bottom
Top
Middle
Anywhere
What will be the output after performing operations: push(10), push(20), pop()?
10
20
30
Error
Which data structure is used for undo operations in text editors?
Queue
Array
Stack
Tree
What happens when you pop from an empty stack?
Returns 0
Inserts null
Stack Overflow
Stack Underflow
Which Java class can be used to implement a stack?
java.util.LinkedList
java.util.Stack
java.util.HashMap
java.util.Array
What is the time complexity of push and pop operations in a stack?
O(n)
O(log n)
O(1)
O(n log n)
How many stacks are needed to implement a queue?
1
2
3
None
Which of the following is NOT a valid stack operation?
Push
Pop
Peek
Enqueue
What does peek() do in a stack?
Removes the top element
Shows the top element
Deletes the stack
Adds a new element
Which of the following application uses stack?
Printer Spooler
Job Scheduling
Function Call Management
Buffer Management
Stack is a type of:
Linear Data Structure
Non-linear
Graph
Tree
Which traversal of tree uses stack?
BFS
Inorder
DFS
Level Order
What is the initial value of the top pointer in an empty stack (array implementation)?
-1
0
NULL
1
Which of the following is a disadvantage of stack?
Fast insertion
Limited access
Easy memory management
Dynamic size
In expression evaluation, stack is used for:
Infix evaluation
Prefix evaluation
Postfix evaluation
Bracket removal
Which data structure is used for backtracking?
Queue
Graph
Stack
Heap
Stack overflow occurs when:
Stack underflows
Stack becomes NULL
Stack gets empty
Stack exceeds its size limit
What is the return value of pop() when stack is empty (in most languages)?
-1
Exception or Error
NULL
0
Which of the following is a valid sequence of stack operations?
push(1), push(2), pop(), push(3)
pop(), push(1), push(2)
push(1), enqueue(2)
insert(1), delete(2)
Which of these uses a call stack internally?
Loops
Pointers
Recursive function
Arrays
What happens if too many recursive calls are made without a base case?
Null error
Infinite loop
Stack Underflow
Stack Overflow
What does stack.peek() return after push(7), push(9), push(11)?
7
9
0
11
Which expression format is easiest to evaluate using a stack?
Infix
Postfix
Prefix
Bracketed
What is the main use of stack in system programming?
Store loop counters
Manage heap memory
Manage function calls and local variables
Display output
What is the maximum number of elements that can be stored in a stack of size n?
n+1
n-1
n
Infinite
What is a stack frame?
Stack node
Storage structure for a single function call
Block in heap
Loop block
In array implementation of stack, how is stack underflow checked?
If top == -1
If top == size
If top == NULL
If stack[0] == NULL
Which of the following postfix expressions is valid?
23+5
23+5*
235+
23*+5
What is the result of evaluating the postfix expression 5 6 2 + *?
60
40
70
32
What will be the output of the following Java stack operations? Stack
1
2
3
Stack is empty
Which data structure is best suited for balancing symbols in an expression (like { [ ( ) ] })?
Queue
Stack
Heap
Tree
What is the infix expression for the postfix: A B + C *?
(A + B) * C
A + (B * C)
A + B * C
A * B + C
What is the postfix of the infix: (A + B) * (C - D)?
AB+CD-*
ABC+D-*
A+B*C-D
AB+*CD-
Which of the following will NOT cause StackOverflow?
Infinite loop
Deep recursion
Too many push operations
No pop operation
Which of the following will NOT cause StackOverflow?
Infinite loop
Deep recursion
Too many push operations
No pop operation
Which of the following is used to implement function calls internally in programming languages?
Stack
Queue
Array
Graph
Which is true about peek() operation in stack?
It removes the top element
It throws an exception if the stack is full
It returns the top without removing
It adds an element
What will be the result of this prefix expression: + 3 * 5 6?
33
30
21
18
Which of the following postfix expressions corresponds to the infix A + B * C?
AB+C*
ABC*+
A+BC*
ABC+*
A stack implemented using linked list requires memory for:
Data only
Pointer only
Data and pointer
Just index
If a stack has n elements, what is the time complexity of searching an element?
O(1)
O(log n)
O(n)
O(n log n)
Which traversal method uses a stack?
BFS
Preorder using recursion
Level order
All of the above
In which of the following applications is the stack data structure most extensively used?
File systems
Page replacement algorithms
Expression evaluation
Round Robin scheduling
Which of the following operations can result in an underflow in a stack?
push()
pop()
peek()
insert()
What will be the output of the following operations on an empty stack? Stack
10
20
30
Stack is empty
What is the time complexity of push and pop operations in a stack implemented using an array or linked list?
O(log n)
O(n)
O(1)
O(n log n)
What is the postfix form of the expression: A + B * (C - D)?
AB+CD-*
ABCD-+
AB+C-D
A+BCD*-
Which method is used to return the top element without removing it from the stack in Java?
top()
peek()
pop()
fetch()
What happens if you perform a pop() operation on an empty stack in Java?
Returns -1
Returns null
Throws EmptyStackException
Returns 0
Which of the following is NOT a valid use case for stacks?
Undo operations in editors
Function call management
Graph traversal
CPU scheduling
In stack terminology, which end is considered the top?
The first inserted element
The element at index 0
The most recently inserted element
The element with the highest priority
Which data structure is used to reverse a word or a sentence in programming?
Queue
Stack
List
Graph
Which of the following statements about stacks is FALSE?
Stacks use LIFO principle
Stacks can be used for DFS
Stacks can grow dynamically
Stacks allow direct access to elements
How many stacks are needed to implement a queue using stacks?
1
2
3
0
What will be the result of the postfix expression 7 3 2 * -?
1
-1
7
1
Which Java class provides built-in stack functionality?
Queue
LinkedList
Stack
List
Which of the following is true about stack memory in recursion?
Each recursive call uses the same memory
Recursive calls share the same variables
Stack memory increases with recursion depth
Stack is not involved in recursion
Which of the following postfix expressions is valid and correctly evaluates to 14?
5 3 + 2 *
6 2 * 2 +
4 4 + 2
7 2 3 *
Which of the following is First In First Out (FIFO)?
Stack
Queue
Tree
Graph
Which operation inserts an element in a queue?
Push
Enqueue
Insert
Pop
What operation removes an element from the queue?
Pop
Delete
Dequeue
Peek
Queue insertion happens at the:
Front
Rear
Middle
Top
Queue deletion happens at the:
Rear
Top
Front
End
What is the condition of Queue Overflow?
When front = rear
When queue is full
When queue is empty
When no dequeue occurs
What is the time complexity of enqueue and dequeue?
O(log n)
O(n)
O(n log n)
O(1)
Circular Queue overcomes the problem of:
Insertion
Deletion
Memory Waste
Overflow
What is the default size of Java’s LinkedList queue?
Infinite
10
100
0
Which interface in Java is implemented for a queue?
Stack
Queue
Deque
Map
Priority Queue is:
FIFO
LIFO
Based on priority
Sorted Queue
In which scenario is queue preferred?
Backtracking
Call Stack
Resource Scheduling
Tree Traversal
What is the drawback of a simple queue?
It uses a lot of memory
Insertion is not possible in middle
Space at front is wasted
Deletion is complex
What is the output of the queue after: enqueue(10), enqueue(20), dequeue()?
[10]
[20]
[10, 20]
[]
Which of the following queue types allows insertion and deletion from both ends?
Simple Queue
Priority Queue
Deque
Circular Queue
Which of the following is not a valid queue type?
Simple Queue
Double-Ended Queue
Priority Queue
Binary Queue
In Java, which class is commonly used to implement a queue?
Stack
ArrayList
LinkedList
TreeMap
In Java, which class is commonly used to implement a queue?
Stack
ArrayList
LinkedList
TreeMap
What is the time complexity of accessing the front element in a queue?
O(n)
O(log n)
O(1)
O(n log n)
Which method is used in Java to insert an element in a queue?
add()
insert()
offerLast()
enqueue()
Which method removes the front element of a queue in Java?
pop()
remove()
pollLast()
get()
What happens if you call remove() on an empty Java Queue?
Returns null
Throws NullPointerException
Throws NoSuchElementException
Does nothing
What does the offer() method return if the insertion fails?
true
false
null
throws exception
Which method retrieves but does not remove the head of the queue?
remove()
element()
peek()
poll()
In a circular queue, what condition represents overflow?
rear == size
front == rear
(rear + 1) % size == front
rear == -1
How many pointers are used to manage a circular queue?
1
2
3
4
Which of the following is not an operation on a queue?
Enqueue
Dequeue
Traverse
Peek
What is the result of this operation: enqueue(5), enqueue(8), dequeue(), enqueue(10)?
[5, 8, 10]
[8, 10]
[5, 10]
[10]
What is the purpose of a Deque?
Only insert at front
Insert at front, delete at rear
Insert and delete from both ends
Acts like a stack
Which interface in Java supports Deque implementation?
Queue
List
Deque
Set
What happens when you dequeue from an empty queue?
It wraps to front
It causes overflow
It causes underflow
It returns front
What is the main advantage of a circular queue over a linear queue?
Easy insertion
Better memory utilization
Faster operations
Simpler implementation
In a circular queue, the condition for full queue is:
front == rear
front == -1
(rear + 1) % size == front
rear == size
What is the output of the queue after:
Queue
[1, 2, 3]
[2, 3]
[1, 3]
[3, 2]
Which Java interface is suitable for queue operations?
List
Collection
Queue
Set
What is the role of the offer() method in queues?
Adds to the front
Adds to the rear
Removes from front
Removes from rear
In which situation do we prefer Deque over queue?
When insertion at rear is required
When deletion from front is required
When both ends require insertion/deletion
Never
Priority Queue differs from normal queue in terms of:
Insertion logic
Deletion logic
Both A and B
Memory usage
What will happen if poll() is called on an empty queue?
Exception
Returns -1
Returns null
Inserts 0
What is the correct time complexity of inserting into a priority queue (min-heap)?
O(1)
O(log n)
O(n)
O(n^2)
Which of the following data structures can be used to implement BFS in a graph?
Stack
Queue
Tree
Set
Which of these can be used for implementing undo-redo feature in a browser?
Queue only
Two stacks
Circular Queue
Priority Queue
Which is not a valid operation on a queue?
Dequeue
Peek
Insert front
Offer
Which class is used in Java for a double-ended queue?
Deque
Stack
PriorityQueue
ArrayList
Which queue data structure uses heap internally in Java?
Deque
ArrayDeque
PriorityQueue
BlockingQueue
Queue is the best data structure for:
Recursion
Parsing
Scheduling processes
Sorting
Which of the following is the correct postfix form of the expression: A + B * C?
ABC+*
A + BC*
ABC*+
+A*BC
What is the prefix form of the expression: (A - B) / (C + D)?
-AB/+CD
/-AB+CD
/-AB+CD
/AB+CD-
Convert the infix expression A * (B + C) / D to prefix:
*A/+BCD
/ * A + B C D
/ * A + B C D
/ * A + B C D
The postfix expression for: (A + B) * (C - D) is:
AB+CD-*
AB+*CD-
A+B*C-D
ABCD+-*
Evaluate the postfix expression: 2 3 1 * + 9 -
-4
4
2
0
Which data structure is most suitable for converting infix to postfix?
Array
Queue
Stack
LinkedList
What is the postfix notation for A - B + C?
ABC+-
AB-C+
A-BC+
AB+C-
Prefix form of the expression A + B * (C ^ D - E)?
+A*B^-CDE
+A*B^CDE-
+A*B^-CDE
+A*B^-CDE
Which of the following statements is true?
Postfix uses parentheses to indicate precedence.
Prefix is easier to evaluate using a queue.
Postfix expressions are evaluated from left to right using a stack.
Infix is easier for computers to evaluate.
Evaluate the postfix: 5 1 2 + 4 * + 3 -
10
14
15
16
In a valid postfix expression, operators appear:
Before their operands
After their operands
Between operands
Cannot be determined
Which conversion is correct for: (A + B) * (C - D)
Infix → Prefix: * +AB -CD
Infix → Postfix: AB+CD-*
Infix → Prefix: *+AB-CD
All of the above
What is the prefix of A * B + C / D?
*AB+/CD
+*AB/CD
+AB*/CD
+*ABCD/
Which postfix expression is equivalent to: A + B - C * D?
AB+CD*-
AB+CD*-
ABCD*+-
AB+*CD-
Evaluate: 8 2 / 3 - 2 *
8
6
4
2
The order of evaluation in prefix expressions is:
Right to left
Left to right
Inside to outside
Depends on operators
The infix expression for the postfix: AB+C* is:
A + (B * C)
(A + B) * C
A + B * C
A * (B + C)
Which traversal of an expression tree gives the postfix expression?
Inorder
Postorder
Preorder
Level-order
Which one is a valid prefix expression?
AB+
+AB
A+B
AB+*
What is the postfix of: (A + B * C - D) ^
Which one is a valid prefix expression?
AB+
+AB
A+B
AB+*
What is the postfix of: (A + B * C - D) ^ E ^ F
ABC*+D−EF^^
ABC*+DEF^^-
AB*C+D-EF^^
ABC*+D-EF^^
What is the result of evaluating the postfix expression: 6 2 3 + - 3 8 2 / + *?
10
20
30
40
What is the result of evaluating the postfix expression: 5 6 2 + * 12 4 / -
30
32
28
24
What is the result of evaluating the postfix expression: 7 8 + 3 2 + /
2
3
5
7
What is the result of evaluating the postfix expression: 10 2 8 * + 3 -
23
27
19
20
What is the result of evaluating the postfix expression: 4 5 7 2 + - *
12
10
-8
8
What is the result of evaluating the postfix expression: 3 4 + 2 5 * +
17
27
35
21
What is the result of evaluating the postfix expression: 12 3 / 2 * 4 +
8
12
10
6
What is the result of evaluating the postfix expression: 15 7 1 1 + - / 3 * 2 1 1 + + -
3
5
1
2
What is the result of evaluating the postfix expression: 2 3 1 * + 9 -
-4
4
0
5
What is the result of evaluating the postfix expression: 4 2 + 3 5 1 - * +
24
20
16
22
What is the result of evaluating the postfix expression: 5 1 2 + 4 * + 3 -
14
18
22
16
In postfix evaluation, which data structure is used?
Queue
Stack
Heap
Tree
Postfix expression 2 3 1 * + 9 - evaluates to:
2
5
-4
4
What will be the result of this postfix expression: 4 5 7 2 + - *
4
-16
20
12
Which operator is evaluated first in the expression: 4 5 + 2 3 ^ *?
+
*
^
Depends on precedence
Fill in the blank to evaluate a postfix expression using a stack: for (char ch : expr) { if (Character.isDigit(ch)) { stack.push(ch - '0'); } else { int b = stack.pop(); int a = stack.pop(); int result = // (a) stack.push(result); } }
What is the output of the following Python code? expr = "23*54*+9-" stack = [] for ch in expr: if ch.isdigit(): stack.append(int(ch)) else: b = stack.pop() a = stack.pop() if ch == '*': stack.append(a * b) elif ch == '+': stack.append(a + b) elif ch == '-': stack.append(a - b) print(stack[-1])
17
25
23
18
What will be the output of the following Java code?
String expr = "231*+9-";
Stack
5
4
2
-4
Which of the following can be the output of evaluating this postfix: 8 2 / 3 - 2 *?
5
6
8
4
Identify the correct postfix evaluation function (Java style):
if (isOperator(ch)) { int a = pop(); int b = pop(); push(a + b); }
if (isOperator(ch)) { int b = pop(); int a = pop(); push(a + b); }
if (isOperator(ch)) { int b = pop(); int a = pop(); push(b + a); }
if (isOperator(ch)) { int b = pop(); int a = pop(); push(a - b); }
Which of the following is not a tree traversal method?
Inorder
Preorder
Reverseorder
Postorder
In which traversal is the root node visited first?
Inorder
Preorder
Postorder
Level-order
In a postorder traversal, the root is visited:
First
After the left subtree
After the right subtree
Last
What is the inorder traversal of a binary tree with root 1, left child 2, and right child 3?
1 2 3
2 1 3
3 2 1
2 3 1
Level-order traversal is also known as:
Depth First Traversal
Breadth First Traversal
Postorder Traversal
Spiral Traversal
Which traversal is useful to get the prefix expression of an expression tree?
Inorder
Postorder
Preorder
Level-order
What data structure is used for level-order traversal?
Stack
Queue
Tree
Heap
Which traversal visits left subtree, root, then right subtree?
Preorder
Postorder
Inorder
Level-order
Which traversal is best suited for deleting a tree?
Inorder
Postorder
Preorder
Level-order
Preorder traversal of a binary tree is:
Root → Left → Right
Left → Root → Right
Left → Right → Root
Right → Left → Root
Given a binary tree, if its inorder and preorder traversal are known, which traversal can be constructed uniquely?
Postorder
Level-order
Preorder
Inorder
If inorder traversal of a binary tree is [D, B, E, A, F, C], what is the preorder traversal?
A, B, D, E, C, F
D, B, A, E, C, F
A, D, B, E, F, C
A, B, E, D, C, F
Which traversal method is used to copy a binary tree?
Inorder
Postorder
Preorder
Level-order
In which order do nodes get pushed into a stack for iterative inorder traversal?
Right → Root → Left
Left → Root → Right
Root → Left → Right
Left → Right → Root
Which traversal gives nodes in non-decreasing order for a BST?
Preorder
Postorder
Inorder
Level-order
You are given a binary tree with the preorder traversal [A, B, D, E, C, F]. What is the root?
A
B
D
F
For expression trees, which traversal gives the postfix expression?
Inorder
Preorder
Postorder
Level-order
Which traversal is most appropriate for evaluating an expression tree?
Inorder
Postorder
Preorder
Level-order
In which traversal can you print all the leaf nodes in a left-to-right manner?
