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

31. In the worst case, the number of comparisons needed to search singly linked list of length n for a given element is

  • Option : D
  • Explanation :
    The worst case number of comparison is n. to search any element from singly link list.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


32. Consider the following algorithm for searching for a given number x in an unsorted array A[1 .......n] having n distinct values:
1. Choose an i uniformly at random from 1.. .n;
2. If A[i] = x then Stop else Goto 1;
  Assuming that x is present on A, what is the expected number of comparisons made by the algorithm before it terminates?

  • Option : A
  • Explanation : The expected number of comparison is n.
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


33. The running time of the following algorithm

  • Option : C
  • Explanation :
    Recurrance relation for procedure A (n) is
    T(n) = T √n + 1 if n > 2
    T(n) = 1 if n ≤ 2
    T(n) = 1
    Now, T (n) = T √n + 1
    Put n = 2k, T (2k)= T (2k/2) + 1
    Use S(K) for T (2k) then
    S(K) = S(k/2) + 1
    Apply masters method.
    Klog21 ≅ 1
    So θ (log k)
    Now we know that
    n = 2k so, k= log2n
    So, O(log logn).
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


34. Consider the following three claims
l. (n + k)m = Θ(nm), where k and m are constants
2. 2n + 1 = O(2n)
3. 22n + 1 = O(2n)
Which of these claims are correct?

  • Option : A
  • Explanation :
    Note:- In devotion place change first point by
    1. (n+k)m = O(nm), where k and m are constants.
    1. (n+k)m ≅ O (nm) because k & m are constant
     then growth rate of both the function is same.
    2. 2n+1 ⇒ 2.2n, Here 2 is constant
     So function is 2n. Statement is true.
    3. 22n+1 ⇒ 2.22n ⇒ 2.4n
     So 4n > 2n then 22n+1 ≠ O(2n).
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *


35. Consider the following C function.

  • Option : B
  • Explanation :
    For large value of y
    P = P * (x/i)
    S = S + P
    When i < y and i + +

    Hence S = ex
Cancel reply

Your email address will not be published. Required fields are marked *


Cancel reply

Your email address will not be published. Required fields are marked *