- Question 1: Which of the following is the value of T3(n) where T3(n) is defined as T3(n) = 5*T3(n-1) – 4*T3(n-2)
- C1*5n + C2*4n
- C1 + C2*4n
- C1*2n + C2*4n
- C1*5n + C2*(-4)n
Explanation: The recursion function (equation) seems to have a strange form. Let’s change the variable T2(n) to get an equation of a familiar form; so, we let A(n) = T3(n); then we have:
The characteristic equation of our new differential equation would be:
So, the homogeneous solution to this equation shall be:
As we have defined A(n) = T3(n), the final answer is:
- Question 2: Determine the value of initial condition F(1) in a way that we can have F(n) = (n+2)! as the solution to the following given recursive function:
F(n) = (n+1) * F(n-1) + (n+1)!
Explanation: Through using the iteration technique to solve the given recursive function, we’ll have:
If we continue these derivations, we can easily guess that the answer should be of following form:
The last step (stop point) in iteration method is when we reach the initial condition F(1); therefore, we let k = n-1, and the non-recursive form would be:
In according to the given function F(n) in question, and what we have derived till now:
Finally, as we shall see, the value of F(1) is:
- Question 3: What is the time Complexity of T(n) = 4* T(n/2) + n * log(n!).
- θ(n * log n)
- θ(n2 * log n)
- θ(n2 * log2 n)
Explanation: We know that log(n!) ∈ θ( n * log n ).
Now, the equivalent problem is to analyze the order of the new recursive function:
We can solve this by master theorem. In order to apply master theorem here, we have f(n) = n2 * log(n), and the parameters a (the number of sub-problems), b (the reduction factor), and C equal to 4, 2, and 2, respectively; so, θ( nlogba ), is of θ( n2 ) which lies in the same complexity class of θ( nC = 2 ); therefore, the given recursive function is belong to the case 2 of master theorem.
In according to master theorem, T(n) would be of following order:
- Question 4: Which one gives the best estimation of T(n) complexity?
T (n) = * T(n/2)+ n2 √n+1.
- θ( n2 * √n * log n )
- O( n2 * √n+1 * log n )
- θ( )
- θ( )
- O( n2 * √n ).
Explanation: We know that , and ; so, we can simplify the recursion function as following:
It belongs to the case 3 of the master theorem; so, the asymptotic complexity of T(n) is:
- Question 5: Which asymptotic boundary is not correct for T (n) = T (n/4) + T (3n/4) + n ?
- O( nlog4/3 2 )
- Ω( n )
- O( n * log(n) )
- None of above
Explanation: By master theorem, we can specify the same boundaries as indicated in first two options (A) and (B):
We can find out the correctness of third option by the recurrence tree method. We draw a tree and we can easily guess an appropriate boundary for T(n):
The length of the branches of the recurrence tree cannot be less than hr, and neither can be more than hL; so the following estimations can be inferred:
In according to the two boundaries mentioned above, we also have T(n) ∈ θ( n*log(n) ).
We know that if T(n) ∈ O(n * log(n)), it must be also of O(nlog4/3n); so if we have evaluated the third option first, we actually would have inferred the correctness of option (A) too. However, recurrence trees just give idea on how to guess an appropriate boundary. As someone may give a wrong guess, this method also needs verification or proof that it will not violate the definition of the notations in use. This verification (proof) can be obtained inductively by iterative substitutions into T(n), while considering the notation definitions.
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. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer DSA Live Classes