big o footnote homework--code bit algorithm analysis?
for homework, i given following 8 formula fragments investigate give big-oh footnote controlling time. anybody greatfully tell me i'm right track?
//fragment 1
for(int i = 0; i < n; i++)
sum++;
i'm pondering o(n) bit 1
//fragment 2
for(int i = 0; i < n; i+=2)
sum++;
o(n) bit 2 well
//fragment 3
for(int i = 0; i < n; i++)
for( int j = 0; j < n; j++)
sum++;
o(n^2) bit 3
//fragment 4
for(int i = 0; i < n; i+=2)
sum++;
for(int j = 0; j < n; j++)
sum++;
o(n) bit 4
//fragment 5
for(int i = 0; i < n; i++)
for( int j = 0; j < n * n; j++)
sum++;
o(n^2) bit 5 nonetheless n * n throwing me off bit i'm definitely sure
//fragment 6
for(int i = 0; i < n; i++)
for( int j = 0; j < i; j++)
sum++;
o(n^2) bit 6 well
//fragment 7
for(int i = 0; i < n; i++)
for( int j = 0; j < n * n; j++)
for(int k = 0; k < j; k++)
sum++;
o(n^3) bit 7 nonetheless once again n * n throwing me off
//fragment 8
for(int i = 1; i < n; i = i * 2)
sum++;
o(n) bit 8
Comments
Post a Comment