CARVIEW |
Miscellaneous on Algorithms GATE CS PYQ Quiz
Topic Wise PYQs Quiz on Algorithms Miscellaneous GATE CS from 2025 to 2000
Question 1
The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with n discs is
T(n) = 2T(n − 2) + 2
T(n) = 2T(n − 1) + n
T(n) = 2T(n/2) + 1
T(n) = 2T(n − 1) + 1
Question 2
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ______________.
148
147
146
140
Question 3
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely approximates the maximum input size of a problem that can be solved in 6 minutes?
256
512
1024
2048
Question 4
The secant method is used to find the root of an equation f(x) = 0. It is started from two distinct estimates x
a
and x
b
for the root. It is an iterative procedure involving linear interpolation to a root. The iteration stops if f(x
b
) is very small and then x
b
is the solution. The procedure is given below. Observe that there is an expression which is missing and is marked by? Which is the suitable expression that is to be put in place of? So that it follows all steps of the secant method?
Secant
Initialize: xa, xb, ε, N // ε = convergence indicator
fb = f(xb) i = 0
while (i < N and |fb| > ε) do
i = i + 1 // update counter
xt = ? // missing expression for
// intermediate value
xa = xb // reset xa
xb = xt // reset xb
fb = f(xb) // function value at new xb
end while
if |fb| > ε
then // loop is terminated with i = N
write “Non-convergence”
else
write “return xb”
end if
xb – (fb– f(xa)) fb/ (xb – xa)
xa– (fa– f(xa)) fa/ (xb – xa)
xb – (fb – xa) fb/ (xb – fb(xa)
xa – (xb – xa) fa/ (fb – f(xa))
Question 5
Match the following
List-I
A. Prim’s algorithm for minimum spanning tree
B. Floyd-Warshall algorithm for all pairs shortest paths
C. Mergesort
D. Hamiltonian circuit
List-II
1. Backtracking
2. Greedy method
3. Dynamic programming
4. Divide and conquer
Codes: A B C D
(a) 3 2 4 1
(b) 1 2 4 3
(c) 2 3 4 1
(d) 2 1 3 4
a
b
c
d
Question 6
Suppose you are given an array s[1..n] and a procedure reverse (s, i, j) which reverses the order of elements in a between positions i and j (both inclusive). What does the following sequence do, where 1 <= k <= n:
reverse(s, 1, k) ;
reverse(s, k + 1, n);
reverse(s, l, n);
Rotates s left by k positions
Leaves s unchanged
Reverses all elements of s
None of the above
Question 7
An n x n array v is defined as follows:
v[i, j] = i-j for all i, j, 1 <= i <= n, 1 <= j <= n
The sum of the elements of the array v is
0
n-1
n2 - 3n + 2
n2 (n+1)/2
Question 8
The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity
&thetha;(n)
&thetha;(m)
&thetha;(m + n)
&thetha;(mn)
Question 9
Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers i, j with i < j. Given a shortcut i, j if you are at position i on the number line, you may directly move to j. Suppose T(k) denotes the smallest number of steps needed to move from k to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is a shortcut to 15. Let y and z be such that T(9) = 1 + min(T(y), T(z)). Then the value of the product yz is _____.
50
100
150
200
Question 10
The most appropriate matching for the following pairs
X: depth first search 1: heap
Y: breadth-first search 2: queue
Z: sorting 3: stack
is
X—1 Y—2 Z --3
X—3 Y—1 Z --2
X—3 Y—2 Z--1
X—2 Y—3 Z--1
There are 11 questions to complete.