Made EasyAlgo
Made EasyAlgo
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 :
Chapter 3 :
Chapter 4 :
Description Sheet
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
www.madeeasy.in © Copyright
Algorithms 5
© 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:
}
}
((
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
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
© 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
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
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)
www.madeeasy.in © Copyright