Practice MCQs ST@
Practice MCQs ST@
-3
5
3
-1
Correct Answer : -1
Ques 2 You are given infinite coins of denominaHons 1, 3, 4. What is the minimum number
of coins required to achieve a sum of 7?
1
2
3
4
Correct Answer : 2
Ques 3 You are given infinite coins of denominaHons 3, 5, 7. Which of the following sum
CANNOT be achieved using these coins?
15
16
17
4
Correct Answer : 4
Ques 4 Find the maximum sub-array sum for the given elements.
{2, -1, 3, -4, 1, -2, -1, 5, -4}
3
5
8
6
Correct Answer : 5
Ques 5 You are given infinite coins of denominaHons 1, 3, 4. What is the total number of
ways in which a sum of 7 can be achieved using these coins if the order of the coins is not
important?
4
3
5
6
Correct Answer : 5
Ques 6 You are given infinite coins of denominaHons 5, 7, 9. Which of the following sum
CANNOT be achieved using these coins?
50
21
13
23
Correct Answer : 13
Ques 7 Which graph algorithm is used to find the shortest path in a graph with both posiHve
and negaHve edge weights (but no negaHve weight cycles)?
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Prim’s Algorithm
Ques 8 Which graph traversal algorithm guarantees finding the shortest path in an
unweighted graph?
Depth-First Search
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Breadth-First Search
Correct Answer : Breadth-First Search
Ques 9 Which graph algorithm is used for finding the shortest path from a source node to all
other nodes in a graph with non-negaHve edge weights?
Kruskal's Algorithm
Dijkstra's Algorithm
Bellman-Ford Algorithm
Floyd-Warshall Algorithm
Ques 10 Which of the following is an opHmal algorithm for solving the "0/1 Knapsack"
problem using dynamic programming?
Depth-First Search
Dijkstra’s Algorithm
Dynamic Programming
Greedy Algorithm
Factorial of n
Fibonacci number at posiHon n
Sum of the first n numbers
Prime number at posiHon n
Factorial of n
Fibonacci number at posiHon n
Longest Common Subsequence
Matrix mulHplicaHon
Correct Answer : Finding the number of ways to make change for a given amount
Correct Answer : It can be divided into two sets such that no two verHces within the same
set are adjacent.
Ques 15 Which of the following is TRUE about the Bellman-Ford algorithm for finding the
shortest path in a weighted graph?
Ques 16 Which of the following is not a property of a minimum spanning tree (MST)?
It finds the shortest path in a graph with negaHve edge weights but without negaHve cycles.
It only works with undirected graphs.
It finds the shortest path from a source to only one vertex.
It uses a greedy approach to find the shortest path.
Correct Answer : It finds the shortest path in a graph with negaHve edge weights but
without negaHve cycles.
Ques 18 Which of the following statements is TRUE about the Floyd-Warshall algorithm for
finding shortest paths in a weighted graph?
Correct Answer : It finds the shortest paths between all pairs of nodes and can handle
negaHve edge weights, but no negaHve cycles.
It is typically used for problems with overlapping subproblems and opHmal substructure.
It guarantees an opHmal soluHon by greedy methods.
It uses recursion without memoizaHon.
It is always slower than brute force.
Correct Answer : It is typically used for problems with overlapping subproblems and opHmal
substructure.
Correct Answer : It is used to find the shortest paths between all pairs of nodes.
Correct Answer : It orders verHces such that for every directed edge uv, u appears before v.
Ques 22 Which algorithm can be used to find the minimum spanning tree of a weighted
graph?
Dijkstra’s Algorithm
Bellman-Ford Algorithm
Kruskal’s Algorithm
Depth-First Search
Correct Answer : Maximum profit that can be obtained from the knapsack problem
Ques 26 Which of the following pseudocode computes the maximum sum of a subarray in
an array of integers (also known as Kadane's Algorithm)?
Ques 27 What is the Hme complexity of the Dijkstra algorithm when implemented using a
priority queue (binary heap)?
O(V^2)
O(E log V)
O(V log E)
O(V + E)
Correct Answer : O(E log V)
Ques 28 Which of the following is the Hme complexity of the Dijkstra's Algorithm using a
priority queue implemented with a binary heap?
O(V^2)
O(E log V)
O(V log E)
O(V + E)
Ques 29 What is the space complexity of the "Longest Common Subsequence" problem
when solved using dynamic programming with a 2D array?
O(1)
O(mn), where m and n are the lengths of the two strings
O(m)
O(n)
Correct Answer : O(mn), where m and n are the lengths of the two strings
Ques 30 What is the space complexity of the "Longest Common Subsequence" (LCS)
problem when solved using dynamic programming with a 2D table?
O(1)
O(n)
O(mn), where m and n are the lengths of the two strings
O(n^2)
Correct Answer : O(mn), where m and n are the lengths of the two strings
Ques 31 What is the Hme complexity of the following Java pseudocode that solves the "Rod
Cuvng" problem?
O(n)
O(n^2)
O(n * W)
O(n^3)
Ques 32 What is the Hme complexity of the Floyd-Warshall algorithm for finding all pairs
shortest paths in a graph with V verHces?
O(V^3)
O(V^2)
O(V^2 log V)
O(VE)
Ques 33 What is the space complexity of the "Floyd-Warshall" algorithm for finding all pairs
shortest paths in a graph with V verHces?
O(V^3)
O(V^2)
O(V log V)
O(E * log V)
Ques 34 What is the Hme complexity of the "Bellman-Ford" algorithm for finding the
shortest path in a graph with V verHces and E edges?
O(V^2)
O(E log V)
O(VE)
O(V + E)
Ques 35 Which algorithm is used to find the minimum spanning tree (MST) of a connected,
undirected graph with weighted edges?
Bellman-Ford Algorithm
Dijkstra's Algorithm
Prim's Algorithm
Floyd-Warshall Algorithm
Ques 36 Which of the following is a valid use case for dynamic programming?
Correct Answer : Solving problems with overlapping subproblems and opHmal substructure
Ques 37 Which of the following is NOT a valid use case for dynamic programming?
As a matrix
As a hash map
As an array of linked lists
As a binary tree
Ques 47 What is the primary advantage of KMP over brute force pazern matching?
Faster matching
Avoids redundant comparisons
Works with negaHve weights
Simpler implementaHon
Uses recursion
Uses addiHonal memory
Avoids stack overflow
Reduces Hme complexity
Ques 49 Which of the following is true about Bellman-Ford and Dijkstra's algorithms for
shortest path finding?
Bellman-Ford works only on posiHve weights, while Dijkstra's works on negaHve weights
Both work only for graphs with non-negaHve edge weights
Bellman-Ford can handle negaHve weights, while Dijkstra's cannot
Both can handle graphs with negaHve weights
Correct Answer : Bellman-Ford can handle negaHve weights, while Dijkstra's cannot
Ques 50 Which algorithm is best suited to find the shortest path in a binary maze?
BFS
DFS
Dijkstra
Bellman-Ford
Ques 51 Why is BFS preferred over DFS for shortest paths in an unweighted graph?
Ques 53 What is the key difference between Greedy Algorithms and Dynamic Programming?
OpHmal substructure
Overlapping subproblems
Greedy approach
Both opHmal substructure and overlapping subproblems
OpHmal substructure
Overlapping subproblems
Greedy approach
Both opHmal substructure and overlapping subproblems
Ques 57 In the context of Minimum Spanning Tree (MST), if two edges have the same
weight, what will happen?
Correct Answer : Both Prim’s and Kruskal’s algorithms can choose any of the two edges
Bozom-up approach
Top-down approach
Randomized approach
Brute force
Ques 59 Which of the following best describes the main idea behind Dynamic Programming
(DP) when solving a problem?
Correct Answer : Breaking down a problem into overlapping subproblems and storing their
soluHons to avoid redundant calculaHons.
Ques 60 Which of the following best describes the tabulaHon approach in Dynamic
Programming?
Correct Answer : Building a soluHon iteraHvely by solving all smaller subproblems first and
storing the results in a table.
Ques 63 How does the Floyd-Warshall algorithm detect negaHve weight cycles?
Correct Answer : Decreases the Hme complexity and increases the space complexity
Ques 67 Which of the following problems is not typically solved by dynamic programming?
Ques 69 Which algorithm is preferred for shortest path in weighted graphs with non-
negaHve weights?
BFS
Bellman-Ford
Dijkstra
Floyd-Warshall
Dijkstra’s Algorithm
Prim’s Algorithm
Kruskal’s Algorithm
Borůvka’s Algorithm
Ques 71 Which data structure is essenHal for implemenHng Kruskal’s algorithm efficiently?
Stack
Queue
Disjoint Set (Union-Find)
Heap
Queue
Disjoint Sets
Priority Queue
Stack
Dynamic programming
Greedy
Divide and conquer
Recursion
Ques 74 In the Longest Common Subsequence problem, which of the following approaches
is generally used?
Ques 75 The Fibonacci sequence is a classic example of a problem that can be solved using:
Greedy algorithms
Dynamic programming
Backtracking
Branch and bound
Ques 76 The 0/1 Knapsack problem is best solved using which technique?
Greedy Algorithms
Divide and Conquer
Dynamic Programming
Backtracking
Ques 77 Which technique is most suitable for solving the 0/1 Knapsack problem?
Greedy Algorithms
Divide and Conquer
Dynamic Programming
Backtracking
Dynamic programming
Greedy algorithms
Backtracking
Divide and Conquer
Ques 79 Given a one-dimensional array of integers, you have to find a sub-array with
maximum sum. This is the maximum sub-array sum problem. Which of these methods can
be used to solve the problem?
Dynamic programming
Two for loops (naive method)
Divide and conquer
Dynamic programming, naïve method and Divide and conquer methods
Correct Answer : Dynamic programming, naïve method and Divide and conquer methods
Ques 80 In the Z-value algorithm, which of the following statements correctly describes the
purpose of the Z-array for a given string?
Each entry in the Z-array stores the number of Hmes the string’s characters appear in
alphabeHcal order.
Each entry
𝑍[𝑖] in the Z-array stores the length of the longest substring starHng from 𝑖 that matches a
prefix of the string.
The Z-array values increase for posiHons where the characters are lexicographically larger
than the first character of the string.
The Z-array is only used for strings that are palindromes.
Adjacency matrix
Edge list
Adjacency list
Distance matrix
Ques 82 What is the difference between an edge list and an adjacency matrix?
Correct Answer : Edge list uses less space than adjacency matrix
O(1)
O(n2)
O(n!)
ExponenHal
Ques 85 Consider the recursive implementaHon to find the nth fibonacci number:
int fibo(int n)
if n <= 1
return n
return __________
fibo(n) + fibo(n)
fibo(n) + fibo(n – 1)
fibo(n – 1) + fibo(n + 1)
fibo(n – 1) + fibo(n – 2)
Fibonacci sequence
Prim’s Algorithm
Shortest Path
Tower of Hanoi
Finding MST
Finding all-pairs shortest paths
DetecHng negaHve cycles
Determining graph connecHvity
Ques 88 Which of the following problems is NOT solved using dynamic programming?
Greedy approach
Dynamic programming
Backtracking
Divide and Conquer
In sparse graphs
In dense graphs
In unweighted graphs
In directed graphs
Ques 93 Which of the following statements is TRUE about Prim’s Algorithm for finding a
Minimum Spanning Tree (MST) in a connected, weighted graph?
It always starts with the edge of the minimum weight in the graph.
It grows the MST by selecHng the smallest edge that connects a node in the MST to a node
outside of it.
It only works with graphs that have unique edge weights.
It finds the shortest path between all pairs of nodes in the graph.
Correct Answer : It grows the MST by selecHng the smallest edge that connects a node in the
MST to a node outside of it.
It is marked as visited
It is pushed into the queue
It is revisited in cycles
All its neighbors are explored simultaneously
It uses backtracking
It iteraHvely relaxes edges V-1 Hmes
It calculates all-pairs shortest paths
It discards negaHve cycles
It works in
𝑂(𝑛^2) Hme by expanding around every possible center in the string.
It preprocesses the string by adding special characters to handle even-length palindromes
and achieves
𝑂(𝑛) Hme complexity.
It can only find palindromic substrings of odd length.
The algorithm requires dynamic programming to store intermediate results.
Correct Answer : It preprocesses the string by adding special characters to handle even-
length palindromes and achieves
𝑂(𝑛) Hme complexity.
Correct Answer : It provides a linear ordering of nodes such that for every directed edge
𝑢→𝑣, u appears before 𝑣 in the ordering.
Ques 98 In Dijkstra’s algorithm for finding the shortest path in a graph with non-negaHve
edge weights, which of the following statements is TRUE about how it selects the next node
to process?
It selects the node with the maximum edge weight connected to the start node.
It always processes nodes in the order they were added to the graph.
It selects the unvisited node with the smallest known distance from the starHng node.
It selects nodes randomly and updates distances accordingly.
Correct Answer : It selects the unvisited node with the smallest known distance from the
starHng node.
Ques 99 Why is Dijkstra’s algorithm efficient for shortest paths in weighted graphs?
It is faster
It works with graphs having cycles
It works with negaHve weights
It does not use edge relaxaHon
Ques 101 Which algorithm is efficient for pazern matching with parHal matches?
Naive Algorithm
KMP Algorithm
Binary Search
Z-Algorithm
Ques 102 Which of the following problems is typically solved using dynamic programming?
Knapsack
SorHng
Binary Search
Maximum Flow
Fibonacci sequence
Subset Sum
Knapsack Problem
Minimum Spanning Tree
Ques 104 What does the Z-value array store in the Z-algorithm?
Ques 105 Which of the following problems should be solved using dynamic programming?
Mergesort
Binary search
Longest common subsequence
Quicksort
Ques 106 Which of the following problems is typically solved using dynamic programming
due to subproblem overlap?
Edge List
Adjacency Matrix
Adjacency List
Matrix Tree RepresentaHon
Ques 109 Which of the following is not a valid way to represent a graph?
Edge List
Adjacency Matrix
Adjacency List
Matrix Tree RepresentaHon
Ques 110 In dynamic programming, the technique of storing the previously calculated values
is called ___________
Ques 111 Consider the following code to find the nth fibonacci term using dynamic
programming:
1. int fibo(int n)
2. int fibo_terms[100000] //arr to store the fibonacci numbers
3. fibo_terms[0] = 0
4. fibo_terms[1] = 1
5.
6. for i: 2 to n
7. fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
8.
9. return fibo_terms[n]
Which technique is used by line 7 of the above code?
OpHmal substructure
Overlapping subproblems
MemoizaHon
Greedy substructure
Ques 112 Which of the following is true about a Minimum Spanning Tree (MST)?
MST always has the same weight as the shortest path tree
MST always includes all verHces of the graph
MST is unique for every graph
MST must be a directed acyclic graph
Ques 113 In a complete graph with n verHces, how many edges are there in its minimum
spanning tree?
n
n-1
n+1
2n
Correct Answer : n - 1
Ques 114 In a Depth-First Search (DFS) traversal of a graph, which of the following
statements is TRUE about the order in which nodes are visited?
Nodes closer to the starHng node are always visited first.
Nodes are visited in a recursive manner, going as deep as possible along each path before
backtracking.
Nodes with the highest degree are visited first.
Nodes are visited in the reverse order of their addiHon to the graph.
Correct Answer : Nodes are visited in a recursive manner, going as deep as possible along
each path before backtracking.
Ques 115 When performing a Breadth-First Search (BFS) on an undirected graph from a
given starHng node, which of the following is TRUE about the order in which nodes are
visited?
Nodes are visited in the order they were added to the graph.
Nodes closer to the starHng node in terms of edge distance are visited earlier.
Nodes are visited based on their degree, with higher degree nodes visited first.
Nodes are visited randomly regardless of their distance from the starHng node.
Correct Answer : Nodes closer to the starHng node in terms of edge distance are visited
earlier.
Ques 116 If a graph has negaHve edge weights, which algorithm cannot be used directly?
Prim’s Algorithm
Kruskal’s Algorithm
Borůvka’s Algorithm
None of the above
Ques 117 What is the Hme complexity of Dijkstra’s algorithm using a binary heap and
adjacency list?
O(V + E)
O((V + E) * log V)
O(V^2)
O(V^3)
O(1)
O(n)
On^2)
O(n^3)
Ques 119 What is the space complexity of the divide and conquer algorithm used to find the
maximum sub-array sum?
O(n)
O(1)
O(n!)
O(n2)
Ques 120 What is the space complexity of the following for loop method used to compute
the nth fibonacci term?
int fibo(int n)
if n == 0
return 0
else
prevFib = 0
curFib = 1
for i : 1 to n-1
nextFib = prevFib + curFib
prevFib = curFib
curFib = nextFib
return curFib
O(1)
O(n)
O(n2)
ExponenHal
O(1)
O(V)
O(E)
O(degree of the node)
Ques 122 What is the Hme complexity of Dijkstra’s Algorithm with a priority queue?
O(V^2)
O(E log V)
O(V log E)
O(E^2)
Ques 123 What is the Hme complexity of Kruskal’s algorithm using a union-find data
structure?
O(E log V)
O(V log V)
O(E log E)
O(V^2)
Ques 124 The worst-case Hme complexity of the Knuth-Morris-Praz (KMP) algorithm is:
O(n^2)
O(n log n)
O(n)
O(n + m)
O(n^2)
O(m) only
O(n + m)
None of the above
Ques 126 What is the Hme complexity of KMP string matching algorithm?
O(n^2)
O(n log n)
O(n + m)
O(nm)
Ques 127 What is the Hme complexity of the KMP string matching algorithm?
O(n^2)
O(n log n)
O(n + m)
O(nm)
Ques 128 In the Z-algorithm, what is the Hme complexity of compuHng the Z-values for a
string of length n?
O(n^2)
O(n log n)
O(n)
O(log n)
1. int fibo(int n)
2. int fibo_terms[100000] //arr to store the fibonacci numbers
3. fibo_terms[0] = 0
4. fibo_terms[1] = 1
5.
6. for i: 2 to n
7. fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
8.
9. return fibo_terms[n]
O(1)
O(n)
On^2)
O(n^3)
Ques 130 What is the space complexity of the following dynamic programming
implementaHon used to compute the nth fibonacci term?
int fibo(int n)
int fibo_terms[100000] //arr to store the fibonacci numbers
fibo_terms[0] = 0
fibo_terms[1] = 1
for i: 2 to n
fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
return fibo_terms[n]
O(1)
O(n)
On^2)
O(n^3)
Ques 131 What is the Hme complexity of the following for loop method used to compute the
nth fibonacci term?
int fibo(int n)
if n == 0
return 0
else
prevFib = 0
curFib = 1
for i : 1 to n-1
nextFib = prevFib + curFib
prevFib = curFib
curFib = nextFib
return curFib
O(1)
O(n)
O(n2)
ExponenHal
Ques 132 What is the Hme complexity of the following Java pseudocode that solves the
"Longest Common Subsequence" problem?
```java int lcs(String X, String Y) { int m = X.length(); int n = Y.length(); int dp[][] = new
int[m+1][n+1]; for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i == 0
o(n)
j == 0) { dp[i][j] = 0; } else if (X.charAt(i-1) == Y.charAt(j-1)) { dp[i][j] = dp[i-1][j-1] + 1; } else {
dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]); } } } return dp[m][n]; }```
O(n^2)
O(n * m), where n and m are the lengths of the two strings
Ques 133 What is the Hme complexity of solving Fibonacci using tabulaHon?
O(n)
O(log n)
O(2^n)
O(1)
O(n)
O(n^2)
O(n log n)
O(2^n)
Ques 135 What is the space complexity of an adjacency matrix for a graph with n verHces?
O(n)
O(n^2)
O(n log n)
O(2^n)
Ques 136 What is the space complexity of an adjacency matrix for a graph with n verHces?
O(n)
O(n^2)
O(n log n)
O(n^3)
Ques 137 What is the Hme complexity of the divide and conquer algorithm used to find the
maximum sub-array sum?
O(n)
O(logn)
O(nlogn)
O(n2)
O(n)
O(nW)
O(2^n)
O(log n)
Ques 139 What is the Hme complexity of the Bellman-Ford algorithm for V verHces and E
edges?
O(V^2)
O(V * E)
O(V + E)
O(V^3)
Ques 140 What is the space complexity of an adjacency list for a graph with V verHces and E
edges?
O(V + E)
O(V^2)
O(V log E)
O(VE)
Ques 141 What is the worst-case Hme complexity of BFS on a graph with V verHces and E
edges?
O(V)
O(V + E)
O(E^2)
O(V^2)
O(V)
O(V^2)
O(V + E)
O(V^3)
Ques 143 What is the Hme complexity of Prim’s algorithm using an adjacency matrix for V
verHces?
O(V^2)
O(V + E)
O((V + E) * log V)
O(V^3)
Ques 144 What is the space complexity of an adjacency matrix for a graph with V verHces?
O(V)
O(V^2)
O(E)
O(V + E)
Ques 145 What is the Hme complexity of Floyd-Warshall Algorithm for a graph with V
verHces?
O(VE)
O(V^2)
O(V^3)
O(E log V)
O(VE)
O(V^2)
O(V^3)
O(E log V)
Ques 147 What is the Hme complexity of Floyd-Warshall algorithm for a graph with V
verHces?
O(VE)
O(V^2)
O(V^3)
O(E log V)
Ques 148 What is the space complexity of an adjacency list for a graph with V verHces and E
edges?
O(V^2)
O(V+E)
O(E log V)
O(V+E log V)
Ques 149 What is the space complexity of an adjacency list in a graph with V verHces and E
edges?
O(V^2)
O(V+E)
O(E log V)
O(V+E log V)
O(V+E)
O(VE)
O(E log V)
O(V^2)
Ques 151 What is the Hme complexity of Bellman-Ford algorithm in a graph with V verHces
and E edges?
O(V+E)
O(VE)
O(E log V)
O(V^2)
Ques 152 What is the Hme complexity of the Bellman-Ford algorithm for a graph with V
verHces and E edges?
O(VE)
O(V^2)
O(E log V)
O(V + E)
Ques 153 If an opHmal soluHon can be created for a problem by construcHng opHmal
soluHons for its subproblems, the problem possesses ____________ property.
Overlapping subproblems
OpHmal substructure
MemoizaHon
Greedy
Correct Answer : OpHmal substructure
Ques 154 Consider the following code to find the nth fibonacci term using dynamic
programming:
1. int fibo(int n)
2. int fibo_terms[100000] //arr to store the fibonacci numbers
3. fibo_terms[0] = 0
4. fibo_terms[1] = 1
5.
6. for i: 2 to n
7. fibo_terms[i] = fibo_terms[i - 1] + fibo_terms[i - 2]
8.
9. return fibo_terms[n]
OpHmal substructure
Overlapping subproblems
Both overlapping subproblems and opHmal substructure
Greedy substructure
Ques 155 Consider the following code snippet. Which property is shown by line 4 of the
below code snippet?
OpHmal substructure
Overlapping subproblems
MemoizaHon
Greedy substructure
Correct Answer : OpHmal substructure
Ques 156 In dynamic programming, which property ensures that the soluHon to a problem
can be constructed efficiently from soluHons of smaller subproblems?
Ques 157 What is the key property that allows dynamic programming soluHons to work
efficiently?
OpHmal Substructure
Greedy Choice Property
No overlapping subproblems
Independent decisions
Ques 158 What key feature makes dynamic programming algorithms perform efficiently?
OpHmal Substructure
Greedy Choice Property
No overlapping subproblems
Independent decisions
Ques 159 If an opHmal soluHon can be created for a problem by construcHng opHmal
soluHons for its subproblems, the problem possesses ____________ property.
Overlapping subproblems
OpHmal substructure
MemoizaHon
Greedy
Correct Answer : OpHmal substructure
Ques 161 If a problem can be broken into subproblems which are reused several Hmes, the
problem possesses ____________ property.
Overlapping subproblems
OpHmal substructure
MemoizaHon
Greedy
Ques 162 Suppose we find the 8th term using the recursive implementaHon. The arguments
passed to the funcHon calls will be as follows:
fibonacci(8)
fibonacci(7) + fibonacci(6)
fibonacci(6) + fibonacci(5) + fibonacci(5) + fibonacci(4)
fibonacci(5) + fibonacci(4) + fibonacci(4) + fibonacci(3) + fibonacci(4)
+ fibonacci(3) + fibonacci(3) + fibonacci(2)
:
:
:
Which property is shown by the above funcHon calls?
Overlapping subproblems
OpHmal substructure
MemoizaHon
Greedy
Z-array
Prefix-suffix (LPS) array
Suffix array
None of the above
Ques 165 Consider the following code to find the nth fibonacci term:
int fibo(int n)
if n == 0
return 0
else
prevFib = 0
curFib = 1
for i : 1 to n-1
nextFib = prevFib + curFib
__________
__________
return curFib
Complete the above code.
prevFib = curFib
curFib = curFib
prevFib = nextFib
curFib = prevFib
prevFib = curFib
curFib = nextFib
prevFib = nextFib
nextFib = curFib
Ques 166 What is the primary difference between Prim’s and Kruskal’s algorithms for finding
a minimum spanning tree?
Correct Answer : Prim’s builds the tree one node at a Hme, while Kruskal’s builds it by edges
Ques 167 What is the primary difference between Prim’s and Kruskal’s algorithms?
Ques 168 In Prim’s algorithm, which data structure is o|en used to select the minimum
weight edge?
Disjoint Set
Priority Queue
Stack
Queue
Ques 169 What core feature do problems suitable for dynamic programming share?
Ques 170 What is the key characterisHc of problems solved by dynamic programming?
Ques 171 Which data structure is commonly used for BFS traversal?
Stack
Queue
Priority Queue
Set
Recursion
Dynamic programming
A single for loop
Recursion, Dynamic Programming, For loops
Ques 173 What is the key advantage of the KMP algorithm over brute force pazern
matching?
Ques 175 Which of the following cannot be solved using BFS in a binary maze?
Relaxing edges
SorHng edges by weight
Traversing verHces
CalculaHng shortest path
Ques 177 Which data structure is commonly used for DFS traversal?
Stack
Queue
Priority Queue
Hash Map
Ques 179 In the KMP algorithm, what is the purpose of the prefix table (pi-table)?
Track mismatches
Record shi|s in pazern
Store pazern frequencies
Store longest prefix-suffix match
Ques 180 In the KMP algorithm, the purpose of the LPS array is to:
Ques 181 Which approach to solving the Fibonacci problem uses tabulaHon?
Recursion
Storing soluHons in a table iteraHvely
Backtracking
Greedy approach
Ques 183 What is the core feature of problems solved by dynamic programming?
Greedy property
Subproblem overlap
Divide and conquer
Random selecHon
Ques 184 For an undirected graph, how is the adjacency matrix represented?
Symmetrical
Asymmetrical
Diagonal
Random
Ques 185 How is the adjacency matrix represented for an undirected graph?
Symmetrical
Asymmetrical
Diagonal
Random
Ques 187 In Kruskal’s Algorithm for finding a Minimum Spanning Tree (MST), which of the
following is TRUE about how edges are processed to ensure that cycles are avoided in the
MST?
Edges are added to the MST in the order they appear in the graph’s adjacency list.
The algorithm uses a union-find (disjoint-set) data structure to detect and prevent cycles by
tracking connected components of nodes.
It relies on a breadth-first search (BFS) to avoid cycles while adding edges.
It only works on graphs with unique edge weights to ensure no cycles are formed.
Correct Answer : The algorithm uses a union-find (disjoint-set) data structure to detect and
prevent cycles by tracking connected components of nodes.
Ques 188 What is the condiHon to move to the next cell in a binary maze shortest path
problem?
Ques 189 What does the priority queue store in Dijkstra’s algorithm?
Ques 191 In a Directed Acyclic Graph (DAG), which of the following statements about
topological sorHng is CORRECT in terms of the number of possible topological orders?
Correct Answer : The number of possible topological orderings depends on the structure of
the DAG, with more than one order possible when mulHple verHces share dependencies.
Ques 192 In the KMP (Knuth-Morris-Praz) algorithm, which of the following statements is
TRUE about the construcHon and use of the prefix funcHon (or LPS array)?
The prefix funcHon records the longest proper prefix of the pazern that is also a suffix,
helping avoid unnecessary comparisons.
The prefix funcHon stores the number of occurrences of each character in the pazern.
The prefix funcHon is recalculated from scratch each Hme a mismatch occurs.
The prefix funcHon is only needed if the pazern contains repeaHng characters.
Correct Answer : The prefix funcHon records the longest proper prefix of the pazern that is
also a suffix, helping avoid unnecessary comparisons.
Ques 193 In Dynamic Programming, what is the primary purpose of using memoizaHon?
Ques 195 What is the purpose of the prefix table (pi-table) in the KMP algorithm?
Ques 196 What role does the prefix table (pi-table) play in the KMP algorithm?
Number of verHces
Number of edges
Total edge weight
Maximum degree of verHces
Ques 200 Which of the following problems can be solved by applying dynamic programming
with overlapping subproblems and opHmal substructure properHes?
Ques 201 What data structure is essenHal for implemenHng Kruskal’s algorithm efficiently?
Binary Heap
Union-Find
Stack
Queue
Binary Heap
Union-Find
Stack
Queue
Ques 204 How many Hmes are the edges relaxed in Bellman-Ford algorithm in a graph with
V verHces?
V
V-1
V+1
E
Ques 205 In a graph with 'V' verHces, how many Hmes are the edges relaxed in the Bellman-
Ford algorithm?
V
V-1
V+1
E
V
V-1
V+1
E
Ques 207 What is the main advantage of Floyd-Warshall algorithm over Dijkstra's algorithm?
Ques 208 What is the main advantage of the Floyd-Warshall algorithm over Dijkstra’s
algorithm?
Faster execuHon
Works for negaHve weight cycles
Simpler implementaHon
Works on undirected graphs
Ques 209 What is the primary advantage of Floyd-Warshall Algorithm over Dijkstra’s
Algorithm?
Faster execuHon
Works for negaHve weight cycles
Simpler implementaHon
Works on undirected graphs
Simpler implementaHon
Works with negaHve weights
Faster for dense graphs
Requires fewer iteraHons
Ques 211 What is the main advantage of the Bellman-Ford algorithm over Dijkstra’s
algorithm?
Simpler implementaHon
Works with negaHve weights
Faster for dense graphs
Requires fewer iteraHons
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :
Correct Answer :