Dsa Q6 PDF
Dsa Q6 PDF
Dsa Q6 PDF
(SET: 1)
Q.1 The running time of an algorithm T(n), where ‘n’ is the input size, is given by—
n
T(n) = 8 ⌈( ) + qn, if n > 1⌉ = p, if n = 1
2
where p, q are constants. The order of this algorithm is—
(a) n2 (b) nn
(c) n3 (d) n
Q.2 An algorithm is made up of 2 modules M1 and M2. If order of M1 is f(n) and M2 is g(n) then
the order of the algorithm is—
(a) it can be used to decide the best algorithm that solves a given problem
(b) it determines the maximum size of a problem that can be solved in a given system, in a given
amount of time
(c) it is the lower bound of the growth rate of the algorithm
(d) Both (a) and (b)
Q.4 The running time T(n), where ‘n’ is the input size, of a recursive algorithm is given as
follows—
T(n)= C+T(n-1), if n>1
= d, if n≤ 1
Q.5 There are 4 different algorithms. A1, A2, A3, A4 to solve a given problem with the order
log(n), log(log(n)), nlog(n), n/log(n) respectively. Which is the best algorithm?
1
(a) A1 (b) A2
(c) A4 (d) A3
Q.6 The time complexity of an algorithm T(n), where n is the input size, is given by—
T(n)= T(n-1) + 1/n, if n>1
= 1, otherwise.
Q.8 What should be the relation between T(1), T(2) and T(3), so that Q.7, gives an algorithm
whose order is constant?
(a) n (b) n2
(c) nlog(n) (d) log(n)
Q.10 The recurrence relation that arises in relation with the complexity of binary search, ‘O’—
2
Q.11 Consider the following 2 functions:
T(1)= 1, if n=1
n
= 2T (⌊2⌋) + √n, for n ≥ 2
int gcd(n, m)
{ if(n%m2=0) return m;
n= n%m;
return gcd(m, n);
}
3
}
Q.15 An array of n numbers is given, where n is an even number. The maximum as well as the
minimum of these n numbers needs to be determined. Which of the following is TRUE about the
no. of comparisons needed?
Let T(n) denote the no. of times the ‘for’ loop is executed by the program on input n. Which of
the following is TRUE?
4
Q.17 The minimum no. of comparisons required to determine if an integer appears more than n/2
times in a sorted array of n integers.
The next two questions(Q.18 & Q.19) are based on the following:
int f1 (int n)
{
if (n= =0 || n= =1)
return n;
else
return (2*f1 (n-1) + 3*f1 (n-2));
}
int f2 (int n)
{
int i;
int X[N], Y[N], Z[N];
X[0]=Y[0]=Z[0]=0;
X[1]=1; Y[1]=2; Z[1]=3;
for (i=2, i≤ n, i++) {
X[i]= Y[i-1] + Z[i-2];
Y[i]= 2 * X[i];
Z[i] = 3 * X[i];
}
return X[n];
5
Q.20 The running time of the algorithm is represented by following recurrence relation:
T(n)= n, if n≤ 3
T(n/3) + Cn, otherwise