# How to calculate Complexity Time O()? [duplicate]

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: • 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) ?
– ykh
Sep 27 '13 at 14:11
• 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). Sep 27 '13 at 14:15
• So it needs someone genius....
– ykh
Sep 27 '13 at 14:19
• 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. Sep 27 '13 at 14:35
• How did you come up with the logn in the summation ?
– ykh
Sep 27 '13 at 15:46