All Topics Quiz

Timer: 0s

Question 1
What is the base condition for merge sort in a doubly linked list?
When head is null or head.next is null
When list size is even
When head.prev is null
When tail.next is null
Question 2
What is the purpose of the split function in merge sort on DLL?
To reverse the list
To split the list into two halves
To delete the middle node
To find and move the max node
Question 3
What is the time complexity of merge sort on a doubly linked list?
O(n)
O(n log n)
O(n²)
O(log n)
Question 4
Which traversal direction(s) can be used in a doubly linked list?
Only forward
Only backward
Both forward and backward
None
Question 5
What is the key operation during the merge step of merge sort for DLL?
In-place reversal
Merge two sorted lists
Delete duplicates
Apply stack-based recursion
Question 6
What does a Minimum Stack track in addition to values?
Stack size
Current minimum value
Average of all values
Maximum value
Question 7
Which additional data structure is often used in implementing a minimum stack?
Queue
Set
Auxiliary stack
Tree
Question 8
What is the time complexity for retrieving the minimum element in a minimum stack?
O(n)
O(log n)
O(1)
O(n²)
Question 9
What happens during a push operation in a minimum stack?
Only push onto one stack
Push only if smaller
Push into both main and auxiliary stacks
Always push null values
Question 10
How does a pop operation affect the minimum stack?
Pops only from main stack
Pops only from auxiliary stack
Pops from both stacks
Pops from queue
Question 11
In the celebrity problem, how many people must a celebrity know?
All
One
None
Half
Question 12
Who must know the celebrity?
Nobody
Only friends
Everyone else
Only people who are not celebrities
Question 13
What is the optimal time complexity of solving the celebrity problem?
O(n)
O(n²)
O(log n)
O(1)
Question 14
Which data structure is commonly used in the brute-force solution of the celebrity problem?
Queue
Matrix
Tree
Graph
Question 15
Which condition identifies person A as not a celebrity when checking against B?
A knows B
B knows A
A doesn't know B
A is equal to B
Question 16
How many total moves are required to solve Tower of Hanoi with n disks?
n
2^n
2^n - 1
Question 17
In the iterative version, what determines whether a move is between source and destination?
Disk size
Iteration number
Whether n is even or odd
Current stack size
Question 18
What is the data structure used to simulate Tower of Hanoi iteratively?
Queue
Stack
Tree
Graph
Question 19
What is the first move in iterative Tower of Hanoi when n is even?
Source → Destination
Source → Auxiliary
Destination → Auxiliary
Auxiliary → Source
Question 20
What happens if the move is not legal in iterative Tower of Hanoi?
Skip
Move smaller disk only
Move larger disk
Terminate
Question 21
What does the stock span value indicate?
Highest price
How many consecutive days price was higher
Days until next price drop
Number of days the price was less than or equal
Question 22
What data structure is used for efficient stock span calculation?
Queue
Stack
Heap
Set
Question 23
What is the worst-case time complexity for calculating spans for n days?
O(n log n)
O(n²)
O(n)
O(log n)
Question 24
What is pushed onto the stack during the stock span algorithm?
Prices only
Spans
Indices
Both prices and indices
Question 25
When is the stack popped during the stock span calculation?
When the current price is lower than the top
When the current price is higher than the top
When stack is full
Never
Question 26
What is stored in each node of a priority queue using DLL?
Value only
Priority only
Value and priority
Index
Question 27
What operation determines the ordering of elements in a DLL-based priority queue?
Arrival time
Priority comparison
Random sorting
Stack order
Question 28
Where is the highest priority node placed in a max-priority queue?
At the end
At the front
Randomly
Middle
Question 29
Which method is efficient for inserting into a sorted DLL priority queue?
Insert at head
Linear search for position
Insert at tail
Binary search
Question 30
What is the time complexity for insertion in a sorted DLL priority queue?
O(log n)
O(n)
O(1)
O(n²)
Question 31
Which technique allows sorting an array in-place without extra space?
Quick Sort
Merge Sort
Counting Sort
Radix Sort
Question 32
What is the space complexity of in-place sorting?
O(1)
O(log n)
O(n)
O(n²)
Question 33
Which sorting algorithm is not in-place?
Selection Sort
Heap Sort
Merge Sort
Insertion Sort
Question 34
What does "in-place" mean in sorting context?
No comparisons
Uses O(1) extra space
Requires recursion
Uses stack
Question 35
Can quicksort be modified to use in-place sorting?
No
Yes
Only for integers
Only if array is sorted
Question 36
What is the goal of the sliding window maximum problem?
Find min element
Find max in each window
Count window elements
Sum all elements
Question 37
Which data structure is optimal for solving sliding window maximum?
Stack
Heap
Queue/Deque
Tree
Question 38
What is the time complexity using deque for sliding window maximum?
O(n log n)
O(n)
O(n²)
O(n³)
Question 39
When is an index removed from the front of the deque?
When it holds min
When it's out of window
When it is repeated
When it's not the last
Question 40
What is stored in deque in sliding window algorithm?
Values
Indices
Windows
Maximums only
Question 41
Stack permutations are related to which type of traversal?
Preorder
Inorder
Stack simulation
DFS only
Question 42
Which condition must be met for a sequence to be a valid stack permutation?
Elements in reverse
Order of popping matches permutation
No repeats
Even number of elements
Question 43
In recovering BST, what data is required?
Parent pointers
Inorder traversal
Postorder traversal
Level order traversal
Question 44
How many nodes are swapped in a BST that needs recovery?
1
2
3
All
Question 45
What is the key step in recovering a BST with two swapped nodes?
Delete and reinsert
Rebuild BST
Identify and swap back
Change root only
Question 46
Which traversal is used in Top View of a binary tree?
DFS
Inorder
Level Order + Horizontal Distance
Postorder
Question 47
In Bottom View, which node is preferred at a horizontal distance?
Topmost
Leftmost
Rightmost
Bottommost
Question 48
What is the key value stored to distinguish positions in views?
Depth
Height
Horizontal Distance
Parent Value
Question 49
Right View of a tree can be extracted using which traversal method?
BFS right to left
DFS right first
DFS left first
Postorder
Question 50
What is required for Left View of a tree?
Preorder
Maximum level tracking
Inorder
Postorder
Question 51
Vertical order traversal uses which two parameters?
Level and index
Horizontal distance and level
Height and depth
Stack and queue
Question 52
What data structure is used to group nodes by horizontal distance?
Stack
TreeSet
HashMap or TreeMap
Queue
Question 53
What traversal ensures proper grouping in vertical order?
DFS
BFS with coordinates
Postorder
Inorder
Question 54
What order is required when multiple nodes have the same (hd, level)?
Max first
Left to right
Top to bottom
Any order
Question 55
In vertical traversal, nodes in same column are sorted by:
Node value only
Node height only
Level and then value
Parent order
Question 56
What are the three parts of boundary traversal?
Root, Right, Leaf
Left boundary, Leaves, Right boundary
Top, Bottom, Leaves
Only Leaves
Question 57
In which order are the boundary nodes printed?
Left to right
Top to bottom
Clockwise
Anti-clockwise
Question 58
Which nodes are excluded in left/right boundary traversal?
Nulls
Root
Leaf nodes
All nodes
Question 59
What traversal is used for collecting leaves?
Postorder
Inorder
Any DFS
BFS only
Question 60
Can a node be repeated in boundary traversal?
No
Yes, always
Yes, only root
Yes, leaves can repeat
Question 61
Which data structure is used for BFS?
Stack
Queue
Deque
Priority Queue
Question 62
DFS can be implemented using:
Stack or Recursion
Queue
Set only
TreeMap
Question 63
What is the time complexity of BFS/DFS in an adjacency list?
O(V)
O(E)
O(V+E)
O(V×E)
Question 64
Which traversal guarantees shortest path in unweighted graph?
DFS
Dijkstra
BFS
A*
Question 65
DFS is best suited for:
Finding shortest path
Finding connected components
Level order printing
Sorting by level
Question 66
Dial's Algorithm is used for graphs with:
Negative weights
Only 0-1 weights
Small non-negative integer weights
Undirected graphs only
Question 67
Which data structure is central in Dial's Algorithm?
Priority queue
Min Heap
Bucket array
Stack
Question 68
Dial's algorithm is a variation of:
DFS
Prim's
Bellman-Ford
Dijkstra's
Question 69
Time complexity of Dial's algorithm is:
O(V+E)
O(E log V)
O(W × V) where W is max edge weight
O(V²)
Question 70
Dial's algorithm is best used when:
Edge weights are floating point
All edge weights are 1
Edge weights are integers in small range
Graph is unconnected
Question 71
What kind of graphs does Bellman-Ford work on?
Undirected only
Weighted with no cycles
Weighted with negative edges
Trees only
Question 72
What is the time complexity of Bellman-Ford algorithm?
O(V+E)
O(E log V)
O(VE)
O(V²)
Question 73
How many times are edges relaxed in Bellman-Ford?
E
V-1
V
E-1
Question 74
What does Bellman-Ford detect that Dijkstra cannot?
Cycles
Negative weight cycles
Minimum spanning tree
DFS path
Question 75
Which condition breaks Bellman-Ford early?
All edge weights same
No changes in any edge relax
Heap is empty
All visited
Question 76
Which graph type supports topological sorting?
Undirected
DAG
Any weighted graph
Tree
Question 77
Which algorithm can be used for topological sort?
Dijkstra
DFS
Kruskal
Prim
Question 78
What happens if a cycle exists in a graph to be topologically sorted?
Sorts partially
Skips cycle
Not possible
DFS fails
Question 79
In Kahn's algorithm, nodes with what indegree are added to queue first?
Maximum
One
Zero
Two
Question 80
How many topological orders are possible for a graph?
One
Zero
Depends on structure
Infinite