GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
59 views

 

 

 

What is the time complexity of the following code snippet? Assume x is a global variable and “statement” takes O(n) time?

 

asked in Algorithms by Active (1.1k points)   | 59 views
T(n) = T(n/2) + O(n)

T(1) = O(1)

Solving this will give:-

T(n) = O(n). :)
I had a question. So there's a difference in 8T(n/2) + O(n) and 8*T(n/2) + O(n) ?
8T(n/2) will be when there are different 8 calls of function n. here 8 is getting multiplied only as a constant.
both are same 8T(n/2) + O(n) and 8*T(n/2) + O(n).

As mentioned above recurrence rlation will be T(n) = T(n/2) + n
Oh yes silly me. Thanks Rishabh and manu :)

Please log in or register to answer this question.



Top Users Sep 2017
  1. Habibkhan

    8586 Points

  2. rishu_darkshadow

    3046 Points

  3. Warrior

    2862 Points

  4. Arjun

    2800 Points

  5. A_i_$_h

    2550 Points

  6. manu00x

    2116 Points

  7. nikunj

    1990 Points

  8. Bikram

    1874 Points

  9. makhdoom ghaya

    1820 Points

  10. SiddharthMahapatra

    1718 Points


26,301 questions
33,864 answers
80,439 comments
31,203 users