I've been struggling with my Analysis of Algorithms and Data Structures homework. With COVID-19 and e-learning, it has been difficult! Especially since my textbook was put on back order :(. I was wondering if any kind soul could help me with analyzing these O(n) problems.
I largely understand it, but I struggle greatly with counting primitive operations on loops, such as for( i = 0; i < 2n; i++ ).
Anyways, I will put them below. I will put my educated guesses below, btw. The biggest part for me is just understanding the primitive operations. Even if I got the right complexity, I still struggled to mathematically arrive at that solution. Thank you so much in advanced!
// #1 O(n)
sum = 0;
for( i = 0; i < 2n; i++ )
sum++;
// #2 O(n^2)
sum = 0;
for( i = 0; i < 2n; i++ )
for( j = 0; j < i; j++ )
sum++;
// #3 O(n^4)
sum = 0;
for( i = 0; i < n2; i++)
for( j = 0; j < i; j++)
sum++;
// #4 O(n^5)
sum = 0;
for( i = 0; i < n; i++)
for( j = 0; j < i*i; j++)
for( k = 0; k < j; k++)
sum++;