PA of Algorithms Q40

0. The time complexity of the following C function is (assume n > 0)

  • Option : D
  • Explanation :
    Recurrence relation for function is
     T (n) = 2 T (n – 1) + 1
       = 2 [2T (n–2) + 1] + 1
       = 4 T (n–2) + 2 + 1
       = 4 [2T (n–3)+1] + 2 + 1
       = 23T (n–3) + 22 + 2 + 1
    2k T (n–k) + 2k-1 + ---2+1
    put n–k = 1
    So 2n-1 T (1) + 2n-2 + ----- 2 + 1
    ⇒ 2n-1 + 2n-2 + --- 2 + 1
    ⇒ 2n-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 *