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
Rose Aashii
0
Newbie Poster
Recommended Answers
Jump to PostCount 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
int Sum = 0;
is 1 basic operation. Thenj = 0;
is another basic operation. Thenj < i
forms …
Jump to PostVery good work !!! Really well explained
Jump to PostHi
Could you please explain how did you come to the result of 3/2N^2... as i cannot figure that out, and i really want to know how to caluclate the time complexity of a given algorithm. I quite understood it that you have to count the steps invovled in …
Jump to PostWhich 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]?
Jump to PostWell i understand 3N, and 3(N - 1) , 3(N-2)..... But i did not really understand, 3(2) + 6, 3(1) + 6 etc, as i think this would be result of replacing the N's value {I am not sure though}.
However, the real difficulty is calculating the actual result. 3/2N^2 …
All 23 Replies
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
brainbox
0
Light Poster
brainbox
0
Light Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
brainbox
0
Light Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
sun_kangane
0
Newbie Poster
WaltP
2,905
Posting Sage w/ dash of thyme
Team Colleague
nashieRbaba
0
Newbie Poster
Rashakil Fol
978
Super Senior Demiposter
Team Colleague
yol
0
Newbie Poster
lulusweety
0
Newbie Poster
Salem
5,138
Posting Sage
lulusweety
0
Newbie Poster
darkagn
315
Veteran Poster
Featured Poster
lulusweety
0
Newbie Poster
jumbo2cool
0
Newbie Poster
sarehu
84
Posting Whiz in Training
haxpor
0
Newbie Poster
ashishforindia
0
Newbie Poster
John_231
commented:
The best you can do is to delete this
+0
Dutchovens
0
Newbie Poster
aadnan.tufail
-3
Newbie Poster
TrustyTony
commented:
Create your own question thread with proof of effort
-3
Ali_84
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.