Algorithms questions — page 2 of 7

Q29

GATE CS 2025 CS-2Graph AlgorithmsMSQ1 mark
Which of the following statements regarding Breadth First Search (BFS) and Depth First Search (DFS) on an undirected simple graph G is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: B, C, D

Q37

GATE CS 2025 CS-2Graph AlgorithmsMCQ2 marks−2/3 if wrong
Let GG be an edge-weighted undirected graph with positive edge weights. Suppose a positive constant α\alpha is added to the weight of every edge.

Which ONE of the following statements is TRUE about the minimum spanning trees (MSTs) and shortest paths (SPs) in GG before and after the edge weight update?
Show answer without attempting

Answer: C

Q41

GATE CS 2025 CS-2Algorithm AnalysisMCQ2 marks−2/3 if wrong
An array AA of length nn with distinct elements is said to be bitonic if there is an index 1≤i≤n1 \le i \le n such that A[1…i]A[1 \dots i] is sorted in the non-decreasing order and A[i+1…n]A[i+1 \dots n] is sorted in the non-increasing order.

Which ONE of the following represents the best possible asymptotic bound for the worst-case number of comparisons by an algorithm that searches for an element in a bitonic array AA?
Show answer without attempting

Answer: D

Q59

GATE CS 2025 CS-2Graph AlgorithmsNAT2 marks
Consider the following algorithm someAlgo that takes an undirected graph GG as input.

someAlgo(GG)
1. Let vv be any vertex in GG. Run BFS on GG starting at vv. Let uu be a vertex in GG at maximum distance from vv as given by the BFS.
2. Run BFS on GG again with uu as the starting vertex. Let zz be the vertex at maximum distance from uu as given by the BFS.
3. Output the distance between uu and zz in GG.

The output of someAlgo(TT) for the tree shown in the given figure is ___________. (Answer in integer)
Question figure
Show answer without attempting

Answer: 6

Q17

GATE CS 2024 CS-1Algorithm AnalysisMCQ1 mark−1/3 if wrong
Given an integer array of size N, we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is
Show answer without attempting

Answer: A

Q42

GATE CS 2024 CS-1Algorithm AnalysisMCQ2 marks−2/3 if wrong
Consider the following recurrence relation:
T(n)={nT(n)+nfor n≥1,1for n=1.T(n) = \begin{cases} \sqrt{n}T(\sqrt{n}) + n & \text{for } n \ge 1, \\ 1 & \text{for } n = 1. \end{cases}
Which one of the following options is CORRECT?
Show answer without attempting

Answer: A

Q45

GATE CS 2024 CS-1Graph AlgorithmsMSQ2 marks
Let GG be a directed graph and TT a depth first search (DFS) spanning tree in GG that is rooted at a vertex vv. Suppose TT is also a breadth first search (BFS) tree in GG, rooted at vv. Which of the following statements is/are TRUE for every such graph GG and tree TT?
More than one option can be correct.
Show answer without attempting

Answer: C

Q60

GATE CS 2024 CS-1Graph AlgorithmsNAT2 marks
The number of edges present in the forest generated by the DFS traversal of an undirected graph GG with 100 vertices is 40. The number of connected components in GG is _________
Show answer without attempting

Answer: 60

Q59

GATE CS 2024 CS-2Graph AlgorithmsNAT2 marks
The number of distinct minimum-weight spanning trees of the following graph is _________
Question figure
Show answer without attempting

Answer: 9

Q20

GATE CS 2023 CSSearching Sorting and HashingMCQ1 mark−1/3 if wrong
An algorithm has to store several keys generated by an adversary in a hash table. The adversary is malicious who tries to maximize the number of collisions. Let kk be the number of keys, mm be the number of slots in the hash table, and k>mk > m.

Which one of the following is the best hashing strategy to counteract the adversary?
Show answer without attempting

Answer: C

Q29

GATE CS 2023 CSAlgorithm AnalysisMSQ1 mark
Let ff and gg be functions of natural numbers given by f(n)=nf(n) = n and g(n)=n2g(n) = n^2.
Which of the following statements is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: A, C

Q54

GATE CS 2023 CSAlgorithm AnalysisMSQ2 marks
Consider functions Function_1 and Function_2 expressed in pseudocode as follows:
Function_1
while n > 1 do
  for i = 1 to n do
    x = x + 1;
  end for
  n = ⌊n/2⌋;
end while

Function_2
for i = 1 to 100 * n do
  x = x + 1;
end for
Let f1(n)f_1(n) and f2(n)f_2(n) denote the number of times the statement "x=x+1x = x + 1" is executed in Function_1 and Function_2, respectively.

Which of the following statements is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: A, D

Q56

GATE CS 2023 CSGraph AlgorithmsNAT2 marks
Let U={1,2,3}U = \{1, 2, 3\}. Let 2U2^U denote the powerset of UU. Consider an undirected graph GG whose vertex set is 2U2^U. For any A,B∈2UA, B \in 2^U, (A,B)(A, B) is an edge in GG if and only if (i) A≠BA \neq B, and (ii) either A⊊BA \subsetneq B or B⊊AB \subsetneq A. For any vertex AA in GG, the set of all possible orderings in which the vertices of GG can be visited in a Breadth First Search (BFS) starting from AA is denoted by B(A)\mathcal{B}(A).

If ∅\emptyset denotes the empty set, then the cardinality of B(∅)\mathcal{B}(\emptyset) is ____________.
Show answer without attempting

Answer: 5040

Q11

GATE CS 2022 CSAlgorithm AnalysisMCQ1 mark−1/3 if wrong
Which one of the following statements is TRUE for all positive functions f(n)f(n)?
Show answer without attempting

Answer: A

Q16

GATE CS 2022 CSSearching Sorting and HashingMCQ1 mark−1/3 if wrong
Suppose we are given nn keys, mm hash table slots, and two simple uniform hash functions h1h_1 and h2h_2. Further suppose our hashing scheme uses h1h_1 for the odd keys and h2h_2 for the even keys. What is the expected number of keys in a slot?
Show answer without attempting

Answer: B

Q49

GATE CS 2022 CSGraph AlgorithmsMSQ2 marks
Consider a simple undirected weighted graph GG, all of whose edge weights are distinct. Which of the following statements about the minimum spanning trees of GG is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: A, B, C

Q2

GATE CS 2021 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Let P be an array containing nn integers. Let tt be the lowest upper bound on the number of comparisons of the array elements, required to find the minimum and maximum values in an arbitrary array of nn elements. Which one of the following choices is correct?
Show answer without attempting

Answer: C

Q3

GATE CS 2021 CS-1Algorithm AnalysisMCQ1 mark−1/3 if wrong
Consider the following three functions.
f1=10nf2=nlog⁡nf3=nnf_1 = 10^n \qquad f_2 = n^{\log n} \qquad f_3 = n^{\sqrt{n}}
Which one of the following options arranges the functions in the increasing order of asymptotic growth rate?
Show answer without attempting

Answer: D

Q9

GATE CS 2021 CS-1Searching Sorting and HashingMCQ1 mark−1/3 if wrong
Consider the following array.
2332456972738997
Which algorithm out of the following options uses the least number of comparisons (among the array elements) to sort the above array in ascending order?
Show answer without attempting

Answer: C

Q17

GATE CS 2021 CS-1Graph AlgorithmsNAT1 mark
Consider the following undirected graph with edge weights as shown:
The number of minimum-weight spanning trees of the graph is ______.
Question figure
Show answer without attempting

Answer: 3

0/200 correct0 marks

Related topics in GATE CS