I am currently doing some exercises with algorithms and I find myself in a huge problem.
It seems that everybody understands this type of problem but I have a really hard time figuring it out. For exercise, we have some for loops to look at, and we need to figure out the runtime for that specific algorithm. We got a solution, which is great and all, but I do not really understand it.
Here is the code for you to look at:
int sum = 0;
for (int n = N; n > 0; n /= 2)
for (int i = 0; i < n; i++)
sum++;
And the solution for this algorithm is O(n)
.
And for our task we need to figure out why the solution is O(n)
(we need to write the Big O notation if you understand what I mean by that 0(1) + O(n)...
for example.)
I have found some explanation for this task on Stack Exchange but I do not understand it at all. I am sorry if you think this is a stupid question but I just started studying software engineering.