So the best and worst case analysis is trivial: they are both the same.

Ignore that, I'm talking out my backside. I blame an absence of caffeine... :O

Neither of those is O(n) at all: and the value of n will have a big impact on the time taken to execute them.

Look at the code more carefully: how many times does the first example loop for the values of n between 0 and 10?

the time complexity for both algorithms i think would be O(n)!

am i right?

then what does our teacher mean by asking what is the time complexity T(n) of this algorithm for the best case and worst case analysis?

`worst`

and`best`

are not defined. :-) The question does no make any certain sense.—SA