I found this excersise in the exam and I ecountered difficulty to solve the problem.
I can suppuse for sure the algorithm will take at least O(n) due the for, but I don't know how to approach the while. I know that in this case i have to evaluate the worst if-else branch and for sure it is the second one.
for i=1...n do
j=n
while i<j do
if j mod 2 = 0 then j=j-1
else j=i
intuitively i think the total cost is: O(nlogn)=O(n)*O(logn)