Data Structures and Algorithms - Performance Analysis of Algorithms and Recurrences

Avatto > > UGC NET COMPUTER SCIENCE > > PRACTICE QUESTIONS > > Data Structures and Algorithms > > Performance Analysis of Algorithms and Recurrences

66. Which one of the following correctly determines the solution of the recurrence relation with T(1)= 1?

  • Option : A
  • Explanation :
    Since f(n) = log n
    a = 2, b = 2
    finding logba using master’s method = log22 = 1
    Hence, f(n) = n'
    So, T(n) = Θ(n)
Cancel reply
Cancel reply

68. Consider the following C function.

 { int i, j, k, p, q = 0;
  for (i = 1; i<n; ++i)
  { P = 0;
    for(j = n; j > 1; j = j/2)
    ++p;
    for (k=l; k<p; k=k*2)
    ++q;
  } return q;
 }
Which one of the following most closely approximates the return value of the function fun1?

  • Option : D
  • Explanation :
    * Outer loop (for i) executed n times.
    * Loop (for j) executed logn times so value of p = logn.
    loop (for k) executed log p times.
    So value of q = log p = log logn.
    for every value of i loop (k) is executed so return value is n * log logn
Cancel reply
Cancel reply

70. Consider a complete binary tree where the left and the right subtrees of the root are maxheaps. The lower bound for the number of operations to convert the tree to a heap is

  • Option : A
  • Explanation :
    The subtrees are already Max-heap, so to make it half, we have to heap if the root, which takes Ω(log n) time.
Cancel reply
Cancel reply