0

How to calculate time complexiy of the following line of code using 'Big-O' or 'Big-OH' notation???

1. scanf("%d",&n);
2. for(i=1,m=n+66;i<=m;i++)
3.      printf("%d \n",i);
4. for(j=n/21,m=n/5;j<=m;j++)
5.      printf("%d \n",j);

I have basic idea but i am getting confused...So, please help me to calculate time complexity of each step,
plus overall complexity.

i have gone through some books and sites but, the explanation is very complex......:(
And according to me the time comlexity of each step is,
1. 1
2. 1+1+(m+1)+(m) // may be true or not
3. 1
4. O(log n) // i know this is wrong
5. 1

PLEASE, correct my answer...

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by Sokurenko
0

wouldnt the first one be O(n) or more precise O(n + 66) ?
second dont know it's just math something line n * 16 can exyst

Edited by Sokurenko: second part too

0

thaks.....
So total complexityis

 O(1)//can be ignored
 O(n+66)
 O(1)
 O(log n)                  OR    log(n/5)..........???

And is it correct????

0

please exlayn how you calculated 4rd line ? from n/21 till n/5 why not other i mean if n is 21 then 21/21 is from 1 till 4.2 like O(n/5) dont know
i am interested in a result too

Edited by Sokurenko: corrected

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.