0% found this document useful (0 votes)
144 views15 pages

Made EasyAlgo

Gate exam

Uploaded by

vartikaraj31.dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views15 pages

Made EasyAlgo

Gate exam

Uploaded by

vartikaraj31.dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CPQ Concept

Practice
2025 Questions

© WWW.MADEEASY.IN
ALGORITHMS

Chapter 1 :
Loop Analysis, Asymptotic Notations and Recursive
Algorithm Methods to Solve Recurrence Relations .............................................................................................3-9

Chapter 2 :

Divide and Conquer


(Quick Sort, Merge Sort, Searching algo Linear Search, Binary Search) ...................................................10-14

Chapter 3 :

Binary Trees, Binary Heaps, Greedy Algorithms ...............................................................................................00-00

Chapter 4 :

Sorting Algorithms, Graph Traversals ....................................................................................................................00-00

„„„„
Description Sheet
ALGORITHMS

Chapter 1 : Loop Analysis, Asymptotic Notations • Binary trees


and Recursive Algorithm Methods to Solve „ Complete binary trees
Recurrence Relations „ Full binary trees
• Time and space complexity of loops • Heap sort
• Independent nested loops • Graph representation
• Dependent nested loops „ Adjacency list representation
• Asymptotic notations „ Adjacency matrix representation
• Worst average and best case analysis • Greedy algorithm
• Recursive algo space complexity „ Single source shortest path algorithm
• Recursive algo time complexity „ Minimal spanning tree
• Methods of solve recurrence relation
Chapter 4 : Sorting Algorithms, Graph Traversals
„ Substitution method
• Comparison based sorting algorithm
„ Recursive tree method
„ Bubble sort
„ Master methods
„ Insertion sort
„ Change of variable methods
„ Selection sort
Chapter 2 : Divide and Conquer (Quick Sort, „ Quick sort
Merge Sort, Searching algo Linear Search, „ Merge sort
Binary Search) „ Heap sort
• Merge sort • Non-comparison based sorting algorithm
• Straight merge sort „ Counting sort
• Quick sort „ Radix sort
• Maximum, minimum algorithm • DFS/BFS algorithm
• Binary search „ Connected components
„ Biconnected components
Chapter 3 : Binary Trees, Binary Heaps, Greedy
„ Strongly connected components
Algorithms
„ Testing of cycle in direct/undirected graph
• Tree representation
• Dynamic programming
„ Array representation
„ Linked list representation „„„„
ALGORITHMS

01 Loop Analysis, A
Recursiv
symptotic N
Asymptotic otations,
Notations,
ecursivee Algorithm and M ethods
Methods
to SSolv
olv
olvee R ecurr
Recurr ence R
ecurrence elations
Relations

Q.1 What does the following algorithm approximate? Let T (n) denote the number of times the for loop
(Assume m > 1, ∈ > 0). is executed by the program on input n. Which
x = m; of the following is TRUE?
y = 1; (a) T (n) = Ο ( n) and T (n) = Ω ( n )
while (x – y > ∈)
(b) T (n) = Ο ( n) and T (n) = Ω(1)
{
(c) T (n) = Ο(n) and T (n) = Ω ( n )
x = (x + y) / 2;
y = m / x; (d) None of the above [GATE-2007]
[GATE-2007]
} Q.4 Consider the following function:
print (x); int unknown (int n)
(a) log m (b) m2 {
(c) m1/2 (d) m1/3 int i, j , k = 0;
[GA TE-2004]
[GATE-2004] for (i = n /2; i <= n ; i++)
for ( j = 2; j <= n ; j = j *2)
Q.2
Q.2 Consider the following C-program fragment in
k = k + n /2;
which i, j and n are integer variables.
return (k);
for (i = n, j = 0; i > 0; i / = 2, j + = i); }
Let Val ( j ) denote the value stored in the variable The return value of the function is
j after termination of the for loop. Which one of (a) Θ(n2) (b) Θ(n2 log n)
the following is true? (c) Θ(n ) 3 (d) Θ(n3 log n)
(a) val ( j ) = Θ(log n) (b) val ( j ) = Θ ( n ) [GA TE-2013]
[GATE-2013]
(c) val ( j ) = Θ(n) (d) val ( j ) = Θ(n log n) Q.5 Consider the following C function:
[GATE-2006]
[GATE-2006] int fun1 (int n)
{ int i, j, k, p, q = 0;
Q.3
Q.3 Consider the following C code segment:
for (i = 1; i < n ; ++i)
int isPrime (n)
{ p = 0;
{ int i, n; for ( j = n; j > 1; j = j / 2)
for (i = 2; i < = sqrt (n); i ++) ++p;
{ if (n mod i == 0) for (k = 1; k < p; k = k *2)
{ ++q ;
printf (“Not Prime”) } return q ;
}
return 0;
Which one of the following most closely
}
approximates the return value of the function fun1?
} (a) n3 (b) n(log n)2
return 1; (c) n log n (d) n log (log n)
} [GATE-2015]
[GATE-2015]

© Copyright www.madeeasy.in
4 CPQ 2025 • Data Science & Artificial Intelligence

Q.6 Consider the following C function: (a) 1 and 2 (b) 1 and 3


int fun {int n) (c) 2 and 3 (d) 1, 2 and 3
{ int i, j ; [GATE-2003]
[GATE-2003]
for (i = 1; i <= n ; i++)
Q.11 Arrange the following functions in increasing
{
asymptotic order:
for ( j = 1; j < n; j + = i)
A. n1/3 B. e n
{
C. n7/4 D. n log9 n
printf{“%d %d”, i, j );
E. 1.0000001n
}
(a) A, D, C, E, B (b) D, A, C, E, B
}
(c) A, C, D, E, B (d) A, C, D, B, E
}
[GA TE-2008]
[GATE-2008]
Time complexity of fun in terms of Θ notation is
Q.12 Two alternative packages A and B are available
(a) Θ(n n ) (b) Θ(n 2 )
for processing a database having 10k records.
(c) Θ(n logn) (d) Θ(n2 logn) Package A requires 0.0001 n2 time units and
[GATE-2017]
[GATE-2017] package B requires 10nlog10n time units to
process n records. What is the smallest value
Q.7
Q.7 Consider the following functions:
of k for which package B will be preferred over A?
f (n) = 3n n (a) 12 (b) 10
g (n) = 2 n log2 n
(c) 6 (d) 5
h(n) = n!
[GATE-2010]
[GATE-2010]
Which of the following is true?
(a) h(n) is Ο(f (n)) (b) h(n) is Ο(g(n)) Q.13 Let W (n) and A (n) denote respectively, the worst
(c) g (n) is not Ο(f(n)) (d) f (n) is Ο( g (n)) case and average case running time of an
[GA TE-2000]
[GATE-2000] algorithm executed on an input of size n. Which
of the following is ALWAYS TRUE?
Q.8
Q.8 Let f (n) = n2 log n and g (n) = n(log n)10 be two
(a) A (n) = Ω(W (n)) (b) A (n) = Θ(W (n))
positive functions of n. Which of the following
(c) A (n) = Ο(W (n)) (d) A (n) = ο(W (n))
statements is correct?
[GA TE-2012]
[GATE-2012]
(a) f (n) = Ο(g (n) and g (n) ≠ Ο(f (n))
(b) g (n) = Ο(f (n) and f (n) ≠ Ο(g (n)) Q.14 Let f (n) = n and g (n) = n(1+sin n), where n is a
(c) f (n) ≠ Ο(g (n)) and g (n) ≠ Ο(f (n)) positive integer. Which of the following
(d) f (n) = Ο(g (n)) and g (n) = Ο(f (n)) statements is/are correct?
[GA TE-2001]
[GATE-2001] I. f (n) = Ο(g (n))
II. f (n) = Ω(g (n))
Q.9
Q.9 If g = Ο(f ) then find true statement from the
(a) Only I (b) Only II
following. (c) Both I and II (d) Neither I nor II
(a) f = Ο(g) (b) g = Θ(f )
[GATE-2015]
[GATE-2015]
(c) f + g = Θ(g) (d) f + g = Θ(f )
Q.15 Write the following statements True or False
Q.15
Q.10 Consider the following three claim:
Q.10
(a) If f (n) = Ο(g (n)) then g (n) = Ο(f (n))
1. (n + k)m = Θ(nm) where k and m are constants
(b) f (n) + Ο(f (n)) = Θ (f (n))
2. 2n + 1 = Ο(2n)
(c) f (n) + ο(f (n)) = Θ (f (n))
3. 22n + 1 = Ο(2n)
(d) (log n)! and (loglog n)! are polynomially
Which of these claim are correct? bounded

www.madeeasy.in © Copyright
Algorithms 5

Q.16 Consider the following functions from positive int f 2( int n)


integers to real numbers: {
int i;
100
10, n , n, log2 n, int X[N], Y[N], Z[N];
n X[1] = 1; Y[1] = 2; Z[1] = 3;
Tire CORRECT arrangement of the above for(i = 2; i < = n ; i++)
functions in increasing order of asymptotic {
complexity is: X[i ] = Y[i – 1] + Z[i – 2];
100 Y[i] = 2 * X[i];
(a) log2 n, , 10, n , n
n Z[i] = 3 * X[i];
}
100
(b) , 10, log2 n, n , n return X[n];
n
}
100
(c) 10, , n , log2 n, n
n Q.18 The running time of f 1(n) and f 2(n) are
100 (a) Θ(n) and Θ(n) (b) Θ(2n) and Ο(n)
(d) , log2 n, 10, n , n
n (c) Θ(n) and Θ(2n) (d) Θ(2n) and Θ(2n)
[GATE-2017]
[GATE-2017] [GA TE-2008]
[GATE-2008]
Q.17 Consider following function f : Q.19 f 1(8) return the values
void f (int n) (a) 1661 (b) 59
{ (c) 1640 (d) 1640
if (n ≤ 0) return; [GATE-2008]
[GATE-2008]
else
{ Q.20 In the following C function, let n ≥ m.
print (n); int gcd (n, m)
f (n – 2); { if (n%m = = 0} return m;
print (n); n = n% m ;
f (n – 1); return gcd (m, n);
} }
}
How many recursive calls are made by this
Let R(n) be recurrence relation which computes function?
sum of values printed by f (n). Then R(n) is (a) Θ(log2n) (b) Ω(n)
(a) R (n – 1) + R (n – 2)
(b) R (n – 1) + R (n – 2) + n (c) Θ(log2log2n) (d) Θ( n )
(c) R (n – 1) + R (n – 2) + 2n [GATE
GATE -2007]
TE-2007]
(d) None of these
Q.21 Let T (n) be the function defined by
Common Data Questions Q.18 and Q.19
 T (1) for n = 1
Consider the following C functions: T (n) = 
2
7T (n / 2) + 18n for n ≥ 2
int f 1(int n)
{ Now which of the following statement is true?
if(n = = 0 n = = 1) return n;
else (a) T (n) = Θ(log2n) (b) T (n)Θ(nlog2 7 )
return (2 * f 1(n – 1) + 3 * f 1(n – 2));
(c) T (n) = Ο(nlog2 n ) (d) None of these
}

© Copyright www.madeeasy.in
6 CPQ 2025 • Data Science & Artificial Intelligence

Q.22 If T1 = Ο(1), match List-I with List-II select the S1 : The time complexity of Bar(n) is θ(n2 log(n)).
correct answer using the codes given below the S2 : The time complexity of Bar(n) is Ω(n2 log(n2)).
Lists: S3 : The time complexity of Bar(n) is Ο(n3 log(n2)).
List-I List-II The number of correct assertions are _______.
A. Tn = Tn – 1 + n 1. Tn = Ο(n) (a) 0 (b) 1
B. Tn = Tn/2 + n 2. Tn = Ο(n2) (c) 2 (d) 3
C. Tn = Tn/2 + n log n 3. Tn = Ο(n log n)
Q.25 What is the time complexity of the following
Q.25
D. Tn = Tn – 1 + log n 4. Tn = Ο(n3)
recursive function:
Codes: int DoSomething ( int n)
A B C D { if (n < = 2)
(a) 2 1 3 3 return 1;
(b) 3 1 4 2 else
(c) 2 3 4 1 return (DoSomething (floor (sqrt (n))) + n);
(d) 3 1 2 4 }
[GATE-1999]
[GATE-1999]
(a) Θ(n2)
Q.23 The recurrence equation:
Q.23 (b) Θ(n log2 n)
T(1) = 1 (c) Θ(log2 n)
T(n) = 2T (n – 1) + n, n ≥ 2 (d) Θ(log2 log2n) [GATE-2007]
[GATE-2007]
evaluates to
Q.26 When n = 22k for some k ≥ 0, the recurrence
(a) 2n + 1 – n – 2 (b) 2n – n
(c) 2n + 1 – 2n – 2 (d) 2n + n relation T (n) = 2 T (n/2) + n , T (1) = 1 evaluates
[GATE-2004]
[GATE-2004] to:

Q.24 Consider the following program:


Q.24 (a) n (logn + 1) (b) n log n
int Bar (int n) (c) n log n (d) n log n
{ [GA TE-2008]
[GATE-2008]
if (n < 2) return; Q.27 Which one of the following correctly determines
else the solution of the recurrence relation with
{ T (1) = 1?
int sum = 0; n
T (n) = 2T   + logn
int i, j ;  2
for (i = 1; i < = 4; i++) Bar (n /2); (a) Θ(n) (b) Θ(n log n)
for (i = 1; i < = n ; j ++) (c) Θ(n2) (d) Θ(log n)
[GA TE-2014]
[GATE-2014]
{
for ( j = 1; j < = i; j ++) Q.28 Find the running time of the following algorithm.
Q.28
{ procedure A(n)
sum = sum + 1; If n < = 2 return (1);

}
}
((
else return A  n  ;
  ))
} (a) Ο(n) (b) Ο(log n)
} (c) Ο(log log n) (d) Ο(1)
Now consider the following statements: [GA TE-2002]
[GATE-2002]

www.madeeasy.in © Copyright
Algorithms 7

Q.29 If T (n) = 3T (n /2) + n, if n >1. T (1) = 1. Then


Q.29 Q.34 Consider the following is true:
T (n) =? T (n) = 2T ([ n ]) + 1, T (1) = 1
(a) Θ(n) (b) Θ(n log2 3
) Which one of the following is true?
log2 3
(c) Θ(n3/2) (d) Θ(n log2 n) (a) T (n) = Θ (log log n) (b) T (n) = Θ (log n)
[DRDO-2008] (c) T (n) = Θ ( n ) (d) T (n) = Θ(n)
[GA TE-2006]
[GATE-2006]
logn −1 log n −1
nr
Q.30 Let S1 = ∑ 2r and S2 = ∑ r 2r . Which of Q.35 The given diagram shows the flow chart for a
r =0 r =0 recursive function A ( n ). Assume that all
the following is true? statements, except for the recursive calls, have
(a) S1 = Θ(n log n), S2 = Θ(n log n) Ο(1) time complexity. If the worst case time
complexity of this function is Ο(n α), then the
(b) S1 = Θ(n), S2 = Θ(n log n)
least possible value (accurate up to two decimal
(c) S1 = Θ(n log n), S2 = Θ(n) positions) of α is _______.
(d) S1 = Θ(n), S2 = Θ(n) Flow chart for Recursive Function A(n)
[DRDO-2008]
Start
Q.31 We have the following recurrence relation:
Q.31
A(n/2)

 1 n≤5
T (n) = 
T (n / 5) + T (3n / 4) + n n > 5 Return A(n/2) A(n/2) A(n /2) Return

Then which of the following statement is TRUE?


A(n/2)
(a) T(n) ∈ Θ(n 2) (b) T (n)∈ Ω( n)
(c) T(n) ∈ Θ(n) (d) T (n) ∈ Θ(n log n)
Return A(n/2) Return
[DRDO-2009]
Q.32 If T1 = Ο(1), give the correct matching for the
following pairs: [GATE-2016]
[GATE-2016]
(m) Tn = Tn – 1 + n (u) Tn = Ο(n)
Q.36 Consider the given recursive algo
(n) Tn = Tn + n (v) Tn = Ο(n logn)
Algo rec(n)
2
{
(o) Tn = Tn /2 + n logn (w) Tn = Ο(n2)
if (n ≤ 1)
(p) Tn = Tn – 1 + logn (x) Tn = Ο(log2 n) return(2)
(a) m – w, n – v, o – u, p – x else
(b) m – w, n – u, o – x, p – v {
(c) m – v, n – w, o – x, p – u x = 2 * rec(n – 1)
(d) m – w, n – u, o – v, p – x call f (x)
[GA TE-1999]
[GATE-1999]
}
Q.33 Let T (n ) be a function defined by the recurrence }
T(n ) = 2T(n/2) + n for n ≥ 2 and T (1) = 1. Which f (x)
of the following statements is TRUE? {
(a) T(n) = Θ(log n) (b) T(n) = Θ( n ) for (i = 1; i ≤ x; i = i * 2)
(c) T(n) = Θ(n) (d) T(n) = Θ(n log n) printf(“MADE EASY”);
[GATE-2005]
[GATE-2005] }

© Copyright www.madeeasy.in
8 CPQ 2025 • Data Science & Artificial Intelligence

Which of the following statements are true? Q.40 Which of the following are asymptotically correct
(a) Time complexity of rec(n) is θ(2n). for T (n )?
(b) Space complexity of rec(n) is θ(n). (a) T n – 1 + n = Ο(n 2 )
(c) Time complexity of rec(n) is θ(n2). (b) T n – 1 + n = Ο(n logn)
(d) Time complexity of rec(n) is θ(n). n
[MSQ] (c) T   + n logn = Ο(n logn)
 2
Q.37 Consider the following recursive algo:
n
(d) T   + n logn = θ(n 2)
Algo rec(n)  2
{ [MSQ]
if (n ≤ 2)
Q.41 Let f (n) = Ω(n), g (n) = Ο(n) and h(n) = Θ(n).
return(1)
Then [f (n) . g(n)] + h(n) is _______
else
(a) Ω(n)
return(2 * rec(sqrt(n)) + 2 * rec(sqrt(n))
(b) Ο(n)
+ log2 n)
(c) Θ(n)
}
(d) None of these
Which of the following statements is/are true?
(a) Time complexity of rec(n) is θ(log n). Q.42 f1 = 10n, f2 = n1/3, f3 = nn, f4 = logn, f5 = 2logn.
(b) Value returns by rec(n) is θ(log2 n). Arrange all these five functions in increasing
(c) Number of fun calls of rec(n) is θ(log n). order.
(d) Space complexity of rec(n) is θ(log n). Q.43 Consider the following function:
[MSQ]
find (int n)
Q.38 Consider given { if (n < 2) then return;
f1 = log n! else
f2 = (log n)! { sum = 0;
f3 = (log n)log n for (i = 1; i ≤ 4; i++) find(n /2);
f4 = (log n)log log n for (i = 1; i ≤ n* n ; i++)
f5 = (log log n)log n sum = sum +1;
(a) f4 f1 f2 f5 f3 (b) f4 f5 f1 f2 f3 }

(c) f4 f1 f5 f2 f3 (d) f1 f2 f4 f5 f3 }
[MSQ] Assume that the division operation takes
constant time and “sum” is global variable. What
Q.39 Let n = m! Which of the following is not true?
is the time complexity of “find (n)”?
(a) m = θ(log n /loglog n) (a) Θ(n2)
(b) m = Ω(log n / loglog n) but not (b) Θ(n2 logn)
m = Ο(log n / loglog n) (c) Θ(n3)
(c) m = θ(log2 n) (d) None of these

(d) m = Ω(log2 n) but not m = Ο(log2 n)


[MSQ]

www.madeeasy.in © Copyright
Algorithms 9

Q.44 Consider the following sorting algorithm: What is the running time of Sorting(A, 1, n)
Sorting (A, low, high) function.
{ if (low = high) return; (a) Θ(n1.7) (b) Θ(n2.7)
if (low +1 = high) (c) Θ(n3.7) (d) Θ(n0.7)
{ if (A[low] > A[high])
Swap (A[low], A[high]); „„„„
return;
}

 high − low + 1
t1 = low +  ;
 3 

 high − low + 1
t2 = low + 2 ⋅   ;
 3
Sorting (A, low, t2);
Sorting (A, t1, high);
Sorting (A, low, t2);
}

© Copyright www.madeeasy.in
ALGORITHMS

02 (Q uick SSor
(Quick or t, M
ort, Merge
Di vide and Conquer
Divide
erge SSor
or t, SSear
ort, earching algo
earching
Linear Search, Binary Search)

Q.1
Q.1 An array A[1 .... n] contains all the integers from L is a list of items from a totally ordered set,
0 to n, except one element. How much time it whose length is a Fibonacci number Fk.
will take to determine the missing integer? {
(a) Ο(n) (b) Ο(log n) If L contains only 1 element, then return L;
(c) Ο(n2) (d) None of these else
{
Q.2
Q.2 For merging two sorted lists of sizes m and n
divide L into L1 (the first Fk – 1 items) and
into a sorted list of size m + n, we required
L2 (the remaining Fk – 2 items)
comparisons of
sorted L1 := FibMergeSorte(L1)
(a) Ο(m) (b) Ο(n)
(c) Ο(m + n) (d) Ο(log m + log n) sorted L2 := FibMergeSort (L2)
[GATE
TE--1995]
[GATE sorted L := Merge(sortedL1, sortedL2)
return sortedL;
Common Data for Q.3 & Q.4 }
In a permutation a1 ... an of n distinct integers, an }
inversion is a pair (ai, aj) such that i < j and ai > aj.
Assuming that the “divide” step in FibMergeSort
Q.3 If all permutations are equally likely, what is the takes constant time (no comparisons) and Merge
expected number of inversions in a randomly behaves similar to the merge in the normal
chosen permutation of 1...n? merge sort. Identify which of the following
(a) n(n – 1)/2 (b) n(n – 1)/4 expressions most closely matches the total
(c) n(n + 1)/4 (d) 2n[log2n] number of comparisons performed by
[GA
GATETE -2003]
TE-2003] FibMergeSort when initially given a list of Fk
elements?
Q.4 What would be the worst case time complexity
(a) Ο(k log k) (b) Ο(K 2)
of the insertion sort algorithm, if the inputs are
(c) Ο(k Fk ) (d) Ο(Fk log k)
restricted to permutations of 1...n with at most
n inversions? Q.6 If one uses straight two-way merge sort
(a) Θ(n 2) (b) Θ(n log n) algorithm to sort the following elements in
(c) Θ(n1.5) (d) Θ(n ) ascending order:
[GA
GATETE-2003]
TE-2003] 20, 47, 15, 8, 9, 4, 40, 30, 12, 17
Then the order of these elements after second
Q.5
Q.5 Let Fk denote the k th Fibonacci number with pass of the algorithm is
Fk = Fk – 1 + Fk – 2 for k ≥ 2, F0 = F1 = 1. (a) 8, 9, 15, 20, 47, 4, 12, 17, 30, 40
Consider the following variation of an merge sort, (b) 8, 15, 20, 47, 4, 9, 30, 40, 12, 17
which assumes that the number of elements in (c) 15, 20, 47, 4, 8, 9, 12, 30, 40, 17
its list argument L is a Fibonacci number Fk. (d) 4, 8, 9, 15, 20, 47, 12, 17, 30, 40
Algorithm FibMergeSort( L ) [GA TE
GATE -1999]
TE-1999]

www.madeeasy.in © Copyright
Algorithms 11

Q.7
Q.7 We are given a sequence of n-numbers a1, a2, Q.14 Suppose you are provided with the following
a3... an, we will assume that all the number are function declaration in the C programming
distinct. We say two indices i < j form an language.
inversion if ai > a j. int partition (int a[ ], int n);
How much time it will take to find total number The function treats the first element of a[ ] as a
of inversions in the given array? pivot, and rearranges the array so that all
(a) Ο(n2) (b) Ο(n log n) elements less than or equal to the pivot is in the
(c) Ο(n) (d) None of these left part of the array, and all elements greater
Q.8
Q.8 Suppose you have k-sorted arrays, each with than the pivot is in the right part. In addition, it
n-elements and you want to combine those moves the pivot so that the pivot is the last
k-sorted arrays into a single sorted array of kn element of the left part. The return value is the
elements. How much time it will take? number of elements in the left part.
(a) Ο(kn) (b) Ο(kn logk) The following partially given function in the C
(c) Ο(k )
2 (d) None of these programming language is used to find the kth
n smallest element in an array a[ ] of size n using
Q.9 Suppose there are 4 sorted lists of elements
4 the partition function. We assume k ≤ n.
each. If we merge these lists into a single sorted int kth_smallest (int a[ ], int n, int k)
list of n elements, for the n = 400 number of {
key comparisons in the worst case using an int left_end = partition (a, n);
efficient algorithm is _________. if (left_end + 1==k)
Q.10 Assume that a merge sort algorithm in the worst {
case takes 30 seconds for an input of size 64. return a [left_end];
Which of the following most closely approximates }
the maximum input size of a problem that can if (left_end+1 > k)
be solved in 6 minutes? {
Q.11 Which of the following is divide and conquer return k th_smallest (______);
application? }
(a) Heapsort (b) Insertion sort else
(c) Bubble sort (d) Merge sort {
[DRDO
[DRDO--2008] return k th_smallest (______);
Q.12 The worst case time complexity of Quicksort }
for n elements when the median is selected as }
the pivot is: The missing argument lists are respectively
(a) Ο(n ) (b) Ο(n2) (a) ( a , left_end, k ) and ( a +left_end+1,
(c) Ο(n log n ) (d) Ο(n log n) n–left_end–1, k–left_end–1)
[DRDO
[DRDO--2008] (b) ( a , left_end, k ) and ( a , n –left_end–1,
Q.13 Randomized quicksort is an extension of
Q.13 k–left_end–1)
quicksort where the pivot is chosen randomly. (c) (a+left_end+1, n–left_end–1, k–left_end–1)
What is the worst case complexity of sorting n and(a, left_end, k)
numbers using randomized quicksort? (d) (a, n–left_end–1, k–left_end–1) and (a ,
(a) Ο(n) (b) Ο(n log n) left_end, k)
(c) Ο(n )
2 (d) Ο(n !)
[GATE
GATE -2015]
TE-2015]
[GA TE
TE--2001]
[GATE

© Copyright www.madeeasy.in
12 CPQ 2025 • Data Science & Artificial Intelligence

Q.15 You are given an infinite array A in which the


Q.15 Q.20 Assume an array A [1, ..., n] has n-elements,
first n-cells contains integers in sorted order and and every element of an array is positive and
the rest of the cells are filled with ∞. If you are less than or equal to n. An element is said to be
not given the value of n, find time complexity of “majority element”, if it is occurred in more than
an algorithm that takes an integer X as input and n
find the position of element X in the given positions of an array. What is the time
2
array A. complexity to check whether the majority element
(a) Ο(n) exist or not in the given array? [Best answer]
(b) Ο(log n) (a) Ο(log n) (b) Ο(n)
(c) Ο(n2) (c) Ο(n log n) (d) Ο(n2)
(d) None of these
Q.21 Binary search can be carried out on a set of
Q.16 The minimum number of comparisons required ordered data items stored in a
to sort 5 elements is (a) Array (b) Stack
(a) 4 (b) 5 (c) Queue (d) List
(c) 6 (d) 7 [DRDO
[DRDO--2008]
[DRDO
[DRDO--2008] Q.22 Given 2-sorted arrays each of n-elements and
Q.22
distinct. How much time it will take to find middle
Q.17 An element in an array X is called a leader if it
element of the union sorted array?
is greater than all elements to the right of it in X.
(a) Ο(1) (b) Ο(log n)
The best algorithm to find all leaders in an array.
(c) Ο(n) (d) None of these
(a) Solves it in linear time using a left to right
pass of the array Q.23 Which of the following statements is true?
(b) Solves in linear time using a right to left pass I. As the number of entries in a hash table
(c) Solves it is using divide and conquer in time increases, the number of collisions increases.
Θ (n log n) II. Recursive programs are efficient
(d) Solves it in time Θ(n 2) III. The worst case complexity for Quicksort is
[GA
GATETE -2006]
TE-2006] Ο(n2)
Q.18 The number of comparisons required to find
Q.18 IV
IV.. Binary search using a linear linked list is
maximum and minimum in the given array of efficient.
n-elements using divide and conquer is _______ (a) I and II (b) II and III
(c) I and IV (d) I and III
 3n   3n 
(a)   (b)   Q.24 Let s be a sorted array of n integers. Let t (n)
 2   2 
denote the time taken for the most efficient
 3n   3n  algorithm to determined if there are two elements
(c)   + 2 (d)   − 2
 2   2  with sum less than 1000 in s. Which of the
following statements is true?
Q.19 An unordered list contains n distinct elements. (a) t (n) is 0(1)
The number of comparisons to find an element (b) n ≤ t (n) ≤ n log2 n
in this list that is neither 2nd maximum nor 2nd
n
minimum is (c) n log2 n ≤ t (n) <  
2
(a) Θ(n log n) (b) Θ(n)
(c) Θ(log n) (d) Θ(1) n
(d) t (n) =   [GATE-2000]
[GATE-2000]
 2

www.madeeasy.in © Copyright
Algorithms 13

Q.25 Consider a list of recursive algorithms and a list Q.26 On which of the following contents of Y and x
of recurrence relations as shown below. Each does the program fail?
recurrence relation corresponds to exactly one (a) Y is [1 2 3 4 5 6 7 8 9 10] and x < 10
algorithm and is used to derive the time (b) Y is [1 3 5 7 9 11 13 15 17 19] and x < 1
complexity of the algorithm. (c) Y is [2 2 2 2 2 2 2 2 2 2] and x > 2
List-I (Recursive Algorithm) (d) Y is [2 4 6 8 10 12 14 16 18 20] and
P. Binary search 2 < x < 20 and x is even
Q. Merge sort [GA TE
GATE -2008]
TE-2008]
R. Quick sort Q.27 The correction needed in the program to make
S. Tower of Hanoi it work properly is
List-II (Recurrence Relation) (a) change line 6 to : if (Y[k] < x) i = k + 1;
I. T (n) = T (n – k) + T (k) + cn else j = k – 1;
II. T (n) = 2T (n – 1) + 1 (b) change line 6 to : if (Y[k] < x) i = k –1; else
j = k +1;
III. T (n) = 2T (n /2) + cn
(c) change line 6 to : if (Y[k] < x) i = k; else j = k;
IV.. T (n) = T (n /2) + 1
IV
(d) change line 7 to : while ((Y[k] = = x) &&
Which of the following is the correct match (i < j ));
between the algorithms and their recurrence [GA
GATETE -2008]
TE-2008]
relations?
Q.28 Given a sorted array of n-elements where other
Q.28
Codes:
than one element x every other element repeat
P Q R S
two times. Then how much time will it take to
(a) II III IV I
find position of x.
(b) IV III I II
(c) III II IV I Q.29 Consider the following statements with respect
(d) IV II I III [GATE
GATE -2004]
TE-2004] to quick sort and select the false options given
below:
Linked Answers Q.
Q.2626 and Q. 27
Q.27 (a) While performing sorting at any iteration only
Consider the following C program that attempts to 1 element can be present at its correct
locate an element x in an array Y[ ] using binary search. position.
The program is erroneous. (b) At first iteration, none of the element
1. f (int Y[10] , int x) { changes its position if given input is already
2. int i, j , k; sorted.
3. i = 0; j = 9; (c) After i th iteration applied on the set of
elements left after (i – 1) iterations if any
4. do {
element is found to be at its correct position,
5. k = (i + j ) / 2; then that element must have been the pivot
6. if (Y[ k ] < x) i = k ; else j = k; for the i th iteration.
7. } while (( Y[k] ! = x) && (i < j )); (d) None of these
8. if (Y[k] = = x) [MSQ]
printf(“x is in the array”) ; Q.30 Which of the following statements are correct?
9. else (a) An insertion algorithm consists of N – 1
printf(“x is not in the array”); passes when an array of N elements is given.
10. } (b) If the input is pre-sorted, the running time is
Ο(N).

© Copyright www.madeeasy.in
14 CPQ 2025 • Data Science & Artificial Intelligence

(c) Insertion sort is stable and it sorts Out-place. Q.33 Given array of n-distinct elements. What is the
(d) When the input array is already sorted then worst case running time to find i th smallest
Merge sort is best suited. element (1 ≤ i ≤ n) from those n elements?
[MSQ] (Select the best answer by assuming n is larger
Q.31 Merging k-sorted lists each of size n /k into one than 50)
sorted list of n-elements using heap sort will (a) Ο(logn) (b) Ο(n)
take how much time? (c) Ο(nlogn) (d) Ο(n2)

Q.32 Consider a modification to merge sort in which


„„„„
m / k sublists each of length k are sorted using
insertion sort and then merged using standard
merge procedure. Then find total time complexity
of modified merge sort.

www.madeeasy.in © Copyright

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy