Prerequisite – Analysis of Algorithms | Set 1, Set 2, Set 3, Set 4, Set 5

**Que-1.** Solve the following recurrence relation?

T(n) = 7T(n/2) + 3n^2 + 2

(a) O(n^2.8)

(b) O(n^3)

(c) ?(n^2.8)

(d) ?(n^3)

**Explanation –**

T(n) = 7T(n/2) + 3n^2 + 2

As one can see from the formula above:

a = 7, b = 2, and f(n) = 3n^2 + 2

So, f(n) = O(n^c), where c = 2.

It falls in master’s theorem case 1:

logb(a) = log2(7) = 2.81 > 2

It follows from the first case of the master theorem that T(n) = ?(n^2.8) and implies O(n^2.8) as well as O(n^3).

Therefore, option (a), (b), and (c) are correct options.

**Que-2.** Sort the following functions in the decreasing order of their asymptotic (big-O) complexity:

f1(n) = n^?n , f2(n) = 2^n, f3(n) = (1.000001)^n , f4(n) = n^(10)*2^(n/2)

(a) f2> f4> f1> f3

(b) f2> f4> f3> f1

(c) f1> f2> f3> f4

(d) f2> f1> f4> f3

**Explanation –**

f2 > f4 because we can write f2(n) = 2^(n/2)*2^(n/2), f4(n) = n^(10)*2^(n/2) which clearly shows that f2 > f4

f4 > f3 because we can write f4(n) = n^10.??2?^n = n10.(1.414)n , which clearly shows f4> f3

f3> f1:

f1 (n) = n^?n take log both side log f1 = ?n log n

f3 (n) = (1.000001)^n take log both side log f3 = n log(1.000001), we can write as log f3 = ?n*?n log(1.000001) and ?n > log(1.000001).

So, correct order is f2> f4> f3> f1. Option (b) is correct.

**Que-3.** f(n) = 2^(2n)

Which of the following correctly represents the above function?

(a) O(2^n)

(b) ?(2^n)

(c) ?(2^n)

(d) None of these

**Explanation –** f(n) = 2^(2n) = 2^n*2^n

Option (a) says f(n)<= c*2n, which is not true.

Option (c) says c1*2n <= f(n) <= c2*2n, lower bound is satisfied but upper bound is not satisfied.

Option (b) says c*2n <= f(n) this condition is satisfied hence option (b) is correct.

**Que-4.** Master’s theorem can be applied on which of the following recurrence relation?

(a) T (n) = 2T (n/2) + 2^n

(b) T (n) = 2T (n/3) + sin(n)

(c) T (n) = T (n-2) + 2n^2 + 1

(d) None of these

**Explanation –** Master theorem can be applied to the recurrence relation of the following type

T (n) = aT(n/b) + f (n) (Dividing Function) & T(n)=aT(n-b)+f(n) (Decreasing function)

Option (a) is wrong because to apply master’s theorem, function f(n) should be polynomial.

Option (b) is wrong because in order to apply master theorem f(n) should be monotonically increasing function.

Option (d) is not the above mentioned type, therefore correct answer is (c) because T (n) = T (n-2) + 2n^2 + 1 will be considered as T (n) = T (n-2) + 2n^2 that is in the form of decreasing function.

**Que-5.** T(n) = 3T(n/2+ 47) + 2n^2 + 10*n – 1/2. T(n) will be

(a) O(n^2)

(b) O(n^(3/2))

(c) O(n log n)

(d) None of these

**Explanation –** For higher values of n, n/2 >> 47, so we can ignore 47, now T(n) will be

T(n) = 3T(n/2)+ 2*n^2 + 10*n – 1/2 = 3T(n/2)+ O(n^2)

Apply master theorem, it is case 3 of master theorem T(n) = O(n^2).

Option (a) is correct.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.