How to give a big O estimate/visualize for these while loop?

680 Views Asked by At

This is from Discrete Mathematics and its applications

enter image description here

enter image description here

I am currently working on problem 4. I was able to see that for problem 2, that one operation one will run n times for every n(meaning in total, the operation will run n^2 times or the big O estimate would be O(n^2)). Is there a similar pattern to problem 4?

1

There are 1 best solutions below

5
On

Each time the loop executes, $i$ is doubled. So if the loop executes $M$ times then $i$ will be $2^M$. But the loop halts when $i > n$. So how big is $M$ when the loop terminates, compared to $n$?