I am looking for some help regarding big O notation. The goal is to give the order of growth for the given code fragments.
int sum = 0
for (int k = n; k > 0; k/=2 )
for (int i = 0; i < k; i++)
sum++;
For this code fragment I got (N logN). The first for loop is logN and the second for loop is N.
int sum = 0
for (int i = 1; i < n; i *= 2 )
for (int j = 0; j < i; j++)
sum++;
I had some trouble on this one. The first for loop is logN, however the second for loop is where I get stuck. The second for loop in dependent on the first for loop. I'm not sure how to show that in big N notation.
int sum = 0
for (int i = 1; i < n; i *= 2 )
for (int j = 0; j < n; j++)
sum++;
The first for loop is logN. The second for loop is N. So this is (N)?
I am struggling with this and would appreciate some help. Thank you