Gate Questions
Gate Questions
Gate Questions
22. The tightest lower bound on the number of comparisons, in the worst case, for comparison-
based sorting is of the order of [GATE CSE 2004]
(A) n
(B) n2
(C) n log n
(D) n log2 n
Solution: Correct answer is (C)
23. The problems 3-SAT and 2-SAT are [GATE CSE 2004]
(A) both in P
(B) both NP-Complete
(C) NP-Complete and in P respectively
(D) Undecidable and NP-Complete respectively
Solution: Correct answer is (C)
26. Which of the following data structures is best suited for implementing a recursive algorithm?
a) Array
b) Linked list
c) Stack
d) Queue
Answer: c) Stack
Explanation: Recursion works on the principle of Last in First Out (LIFO), which is the same principle followed
by the Stack data structure.
a) Quick Sort
b) Dijkstra’s shortest path algorithm
c) Bellman-Ford algorithm
d) Kruskal’s algorithm for minimum spanning tree
Answer: d) Kruskal’s algorithm for minimum spanning tree
Explanation: Greedy algorithms are those algorithms that make the locally optimal choice at each step in the
hope of finding a global optimum. Kruskal’s algorithm is a greedy algorithm as it chooses the edge with the
lowest weight and adds it to the minimum spanning tree.
Explanation: Dynamic programming is a technique where we break a problem down into smaller subproblems
and solve each subproblem only once. Longest Common Subsequence is a problem where we break down the
problem into smaller subproblems and solve them using dynamic programming.
29. Which of the following sorting algorithms has a worst-case time complexity of O(n^2)?
a) Merge Sort
b) Heap Sort
c) Quick Sort
d) Bubble Sort
Explanation: Bubble Sort is an inefficient sorting algorithm with a worst-case time complexity of O(n^2).
30. Which of the following algorithms is used to find the strongly connected components in a
directed graph?
a) Kruskal’s algorithm
b) Prim’s algorithm
c) Floyd-Warshall algorithm
d) Kosaraju’s algorithm
Explanation: Kosaraju’s algorithm is used to find the strongly connected components in a directed graph.
31. Which of the following data structures is best suited for implementing a priority queue?
a) Array
b) Linked list
c) Stack
d) Heap
Answer: d) Heap
Explanation: Priority queues are used to maintain a set of elements with keys. A heap is the best data
structure to implement a priority queue because it provides efficient insertion, deletion, and retrieval of the
minimum (or maximum) element.
32. Which of the following algorithms is used to find the shortest path between two vertices in a
graph?
Explanation: Dijkstra’s algorithm is used to find the shortest path between two vertices in a graph.
33. Which of the following data structures is best suited for implementing a hash table?
a) Array
b) Linked list
c) Stack
d) Queue
Answer: a) Array
34. Which of the following algorithms is used to find the maximum flow in a flow network?
a) Kruskal’s algorithm
b) Prim’s algorithm
c) Ford-Fulkerson algorithm
d) Bellman-Ford algorithm
Explanation: Ford-Fulkerson algorithm is used to find the maximum flow in a flow network.
35. Which of the following algorithms is used to find the minimum spanning tree of a weighted
graph?
a) Kruskal’s algorithm
b) Prim’s algorithm
c) Floyd-Warshall algorithm
d) Bellman-Ford algorithm
36. Which of the following algorithms is used to find the transitive closure of a directed graph?
a) Floyd-Warshall algorithm
b) Bellman-Ford algorithm
c) Kosaraju’s algorithm
d) Depth First Search
Explanation: Floyd-Warshall algorithm is used to find the transitive closure of a directed graph.
37. Which of the following algorithms is used to find the maximum subarray sum?
a) Merge Sort
b) Heap Sort
c) Quick Sort
d) Kadane’s algorithm
38. Which of the following algorithms is used to find the articulation points in a graph?
a) Bellman-Ford algorithm
b) Floyd-Warshall algorithm
c) Depth First Search
d) Kruskal’s algorithm
Explanation: Depth First Search is used to find the articulation points in a graph.
39. Which of the following algorithms is used to find the shortest path between all pairs of vertices
in a graph?
40. Which of the following algorithms is used to find the longest increasing subsequence in a
sequence?
a) Merge Sort
b) Heap Sort
c) Quick Sort
d) Dynamic Programming
Explanation: The longest increasing subsequence problem can be solved using dynamic programming.
41. Which of the following algorithms is used to find the topological order of a directed acyclic
graph?
a) Bellman-Ford algorithm
b) Floyd-Warshall algorithm
c) Depth First Search
d) Kahn’s algorithm
Explanation: Kahn’s algorithm is used to find the topological order of a directed acyclic graph.
42. Which of the following data structures is best suited for implementing a breadth-first search
algorithm?
a) Array
b) Linked list
c) Stack
d) Queue
Answer: d) Queue
43. Which of the following algorithms is used to find the maximum independent set in a graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Depth First Search
d) Bron-Kerbosch algorithm
Explanation: Bron-Kerbosch algorithm is used to find the maximum independent set in a graph.
44. Which of the following algorithms is used to find the diameter of a tree?
45. Which of the following algorithms is used to find the longest path in a directed acyclic graph?
Explanation: Depth First Search is used to find the longest path in a directed acyclic graph.
46. Which of the following algorithms is used to find the minimum number of coins needed to make
change for a given amount?
a) Greedy algorithm
b) Depth First Search
c) Breadth First Search
d) Dijkstra’s shortest path algorithm
Explanation: The minimum coin change problem can be solved using a greedy algorithm.
47. Which of the following algorithms is used to find the maximum flow in a network?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Ford-Fulkerson algorithm
d) Prim’s algorithm
a) Quick Sort
b) Merge Sort
c) Heap Sort
d) Selection algorithm
Explanation: The selection algorithm can be used to find the kth largest element in an unsorted array.
49. Which of the following algorithms is used to find the maximum sum of a subarray with a given
sum constraint?
a) Merge Sort
b) Heap Sort
c) Quick Sort
d) Sliding Window algorithm
Explanation: The maximum sum of a subarray with a given sum constraint can be found using the sliding
window algorithm.
50. Which of the following algorithms is used to find the minimum cut in a network?
a) Bellman-Ford algorithm
b) Floyd-Warshall algorithm
c) Ford-Fulkerson algorithm
d) Prim’s algorithm
51. Which of the following algorithms is used to find the longest common subsequence between
two sequences?
a) Merge Sort
b) Heap Sort
c) Quick Sort
d) Dynamic Programming
Explanation: The longest common subsequence problem can be solved using dynamic programming.
52. Which of the following algorithms is used to find the maximum matching in a bipartite graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Hopcroft-Karp algorithm
d) Kruskal’s algorithm
Explanation: Hopcroft-Karp algorithm is used to find the maximum matching in a bipartite graph.
53. Which of the following algorithms is used to find the minimum vertex cover in a graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Depth First Search
d) Hungarian algorithm
Explanation: Hungarian algorithm is used to find the minimum vertex cover in a graph.
54. Which of the following algorithms is used to find the maximum weighted matching in a
bipartite graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Hungarian algorithm
d) Kruskal’s algorithm
Explanation: Hungarian algorithm is used to find the maximum weighted matching in a bipartite graph.
55. Which of the following algorithms is used to find the minimum path cover in a directed acyclic
graph?
Explanation: Depth First Search is used to find the minimum path cover in a directed acyclic graph.
56. Which of the following algorithms is used to find the minimum spanning tree in a weighted
graph?
a) Dijkstra’s algorithm
b) Prim’s algorithm
c) Bellman-Ford algorithm
d) Kruskal’s algorithm
Explanation: Prim’s algorithm is used to find the minimum spanning tree in a weighted graph.
57. Which of the following algorithms is used to find the all-pairs shortest paths in a weighted
graph?
a) Dijkstra’s algorithm
b) Floyd-Warshall algorithm
c) Bellman-Ford algorithm
d) Kruskal’s algorithm
Explanation: Floyd-Warshall algorithm is used to find the all-pairs shortest paths in a weighted graph.
58. Which of the following algorithms is used to find the convex hull of a set of points?
a) Graham’s scan
b) Quick Sort
c) Merge Sort
d) Heap Sort
Explanation: Graham’s scan is used to find the convex hull of a set of points.
59. Which of the following algorithms is used to find the maximum independent set in a bipartite
graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Depth First Search
d) König’s theorem
Explanation: König’s theorem can be used to find the maximum independent set in a bipartite graph.
60. Which of the following algorithms is used to find the maximum clique in a graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Depth First Search
d) Bron-Kerbosch algorithm
61. Which of the following algorithms is used to find the chromatic number of a graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Depth First Search
d) Greedy algorithm
Explanation: The chromatic number of a graph can be found using a greedy algorithm.
62. Which of the following algorithms is used to find the maximum flow in a network with multiple
sources and sinks?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Dinic’s algorithm
Explanation: Dinic’s algorithm is used to find the maximum flow in a network with multiple sources and sinks.
63. Which of the following algorithms is used to find the shortest path between all pairs of vertices
in a graph with negative edges?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm
Explanation: Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices in a graph
with negative edges.
64. Which of the following algorithms is used to find the maximum flow in a network with
capacities that are fractional numbers?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Push-Relabel algorithm
Explanation: Push-Relabel algorithm is used to find the maximum flow in a network with capacities that are
fractional numbers.
65. Which of the following algorithms is used to find the minimum spanning tree in an undirected
graph with negative edges?
a) Dijkstra’s algorithm
b) Prim’s algorithm
c) Bellman-Ford algorithm
d) Kruskal’s algorithm
Explanation: Bellman-Ford algorithm is used to find the minimum spanning tree in an undirected graph with
negative edges.
66. Which of the following algorithms is used to find the maximum flow in a network with
capacities that can change over time?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Ford-Fulkerson algorithm
Explanation: Ford-Fulkerson algorithm is used to find the maximum flow in a network with capacities that can
change over time.
67. Which of the following algorithms is used to find the shortest path between two vertices in a
graph with negative edges?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm
68. Which of the following algorithms is used to find the maximum flow in a network with
capacities that are integers?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Ford-Fulkerson algorithm
Explanation: Edmonds-Karp algorithm is used to find the maximum flow in a network with capacities that are
integers.
69. Which of the following algorithms is used to find the minimum spanning tree in an undirected
graph with positive and negative edges?
a) Dijkstra’s algorithm
b) Prim’s algorithm
c) Bellman-Ford algorithm
d) Kruskal’s algorithm
Explanation: Bellman-Ford algorithm is used to find the minimum spanning tree in an undirected graph with
positive and negative edges.
70. Which of the following algorithms is used to find the maximum flow in a network with
capacities that can be increased or decreased by a certain amount?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Push-Relabel algorithm
Explanation: Push-Relabel algorithm is used to find the maximum flow in a network with capacities that can
be increased or decreased by a certain amount.
71. Which of the following algorithms is used to find the shortest path between two vertices in a
graph with positive and negative edges?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm
Answer: b) Bellman-Ford algorithm
Explanation: Bellman-Ford algorithm is used to find the shortest path between two vertices in a graph with
positive and negative edges.
72. Which of the following algorithms is used to find the minimum cut in a network with capacities
that are integers?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Ford-Fulkerson algorithm
Explanation: Ford-Fulkerson algorithm is used to find the minimum cut in a network with capacities that are
integers.
73. Which of the following algorithms is used to find the maximum matching in a general graph?
a) Hopcroft-Karp algorithm
b) Edmonds-Karp algorithm
c) Dinic’s algorithm
d) Ford-Fulkerson algorithm
Explanation: Dinic’s algorithm is used to find the maximum matching in a general graph.
74. Which of the following algorithms is used to find the shortest path between all pairs of vertices
in a graph with positive and negative edges?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm
Explanation: Floyd-Warshall algorithm is used to find the shortest path between all pairs of vertices in a graph
with positive and negative edges.
75. Which of the following algorithms is used to find the minimum cut in a network with capacities
that can change over time?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Ford-Fulkerson algorithm
Answer: d) Ford-Fulkerson algorithm
Explanation: Ford-Fulkerson algorithm is used to find the minimum cut in a network with capacities that can
change over time.
76. Which of the following algorithms is used to find the articulation points in an undirected graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Tarjan’s algorithm
d) Hopcroft-Tarjan algorithm
Explanation: Tarjan’s algorithm is used to find the articulation points in an undirected graph.
77. Which of the following algorithms is used to find the bridges in an undirected graph?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Tarjan’s algorithm
d) Hopcroft-Tarjan algorithm
78. Which of the following algorithms is used to find the maximum flow in a network with
capacities that are real numbers?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Ford-Fulkerson algorithm
Explanation: Ford-Fulkerson algorithm is used to find the maximum flow in a network with capacities that are
real numbers.
79. Which of the following algorithms is used to find the maximum flow in a network with
capacities that can be increased or decreased by a real number?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Edmonds-Karp algorithm
d) Push-Relabel algorithm
80. Which of the following algorithms is used to find the shortest path between all pairs of vertices
in a graph with positive edges?
a) Dijkstra’s algorithm
b) Bellman-Ford algorithm
c) Floyd-Warshall algorithm
d) Kruskal’s algorithm