Plz tell me how I would calculate time complexity of the program:

int i = N;

while (i > 0)

{

int Sum = 0;

int j;

for (j = 0; j < i; j++)

Sum++;

cout << Sum << endl;

i--;

}

thnx in advance

Featured Replies

- 2
Count the total number of basic operations, those which take a constant amount of time. That's all there is to it. For example, the code [inlinecode]int Sum = 0;[/inlinecode] is 1 basic operation. Then [inlinecode]j = 0;[/inlinecode] is another basic operation. Then [inlinecode]j < i[/inlinecode] forms yet another basic operation. … Read More

- 1
Which step don't you get? Do you understand how I got to [tex](3N + 6) + (3(N-1) + 6) + \cdots + (3(2) + 6) + (3(1) + 6)[/tex]? Read More

This topic has been dead for over six months. Start a new discussion instead.

Recommended Topics