Q:

How this iterative function is O(n/2) when I calculate it and gives me O(n^3)

I have this function
void A()
{
    for(int i=n/2;i<=n;i++)
        printf("XXX");
}

and I tried to compute it's complexity with the following logic (but I know it's wrong and the correct value is O(n/2) according to tutorial 24:30):

i value  initially starts with i= n/2; then i=(n/2)+1; then i=(n/2)+2; >>>> i=(n/2)+n.

This will lead to total number of execution n/2*(1 +2 +3 +4 + ....+ n)
which will be n^2 definition, therefore it will have a value of O(n^3).

A:

i value initially starts with i= n/2; then i=(n/2)+1; then i=(n/2)+2;
  i=(n/2)+n.

Final value is i=(n/2)+n/2 = n, not (n/2)+n as you assumed; so it is extremely easy to deduce the total number of operations: end - start + 1, which is n - n/2 + 1 = n/2 + 1, and that is O(n).

