I have this problem where in class my professor said that the below statement is O(log(n)) where I thought it was O(n). Could someone please clarify how it is O(log(n))?
Printing a number of magnitude n in binary. Assume that printing each bit requires constant time.
nhave when written in binary notation? It might help to do some examples for small numbers.O(log(n))is alsoO(n). So it is correct to say that there is aO(n)solution to this problem. We can even say that the optimal solution isO(n). However, we will usually say this algorithm isO(log(n))because that is a closer measure of the runtime complexity. As I have suggested in my earlier comments, you should work out some examples to get a better understanding of this analysis.