Can anybody give me a way that i can use to calculate Complexity Time problems, i mean a way that will work on any complex code whatever it was.

I can solve basic problems, but whenever the problem gets a little complex i freeze which means that my way of thinking and solving is wrong.

for example like this:

enter image description here

  • $\begingroup$ I have read many many things, but it doesn't help me solve real problems like the problem above, tell me how is that first loop will result in a log(n) ? $\endgroup$
    – ykh
    Commented Sep 27, 2013 at 14:11
  • $\begingroup$ There can be no general method for computing time complexities because it's not even decidable whether a given program halts at all, let alone whether it does so within some specific number of steps (as a function of the input size). $\endgroup$ Commented Sep 27, 2013 at 14:15
  • $\begingroup$ So it needs someone genius.... $\endgroup$
    – ykh
    Commented Sep 27, 2013 at 14:19
  • $\begingroup$ You can find here some explanations : cs.stackexchange.com/questions/14565/… The usual easiest way is to go from loops to sums and then to analyze these sums, as I did in the link above. $\endgroup$
    – Tpecatte
    Commented Sep 27, 2013 at 14:35
  • $\begingroup$ How did you come up with the logn in the summation ? $\endgroup$
    – ykh
    Commented Sep 27, 2013 at 15:46


Browse other questions tagged or ask your own question.