(Almost) Daily Algorithm Practice: Big O and square roots
Here is today's problem. I was definitely off-base on my first attempt at analyzing the runtime!
If you notice, the algorithm is essentially dividing the problem space into two pieces and analyzing them, effectively running a binary search. This was my initial mistake. I stepped through the problem, was doing all this division crap, forgetting that it's not about the operations that the algorithm itself is running, but rather the approximate number of times it is running said operations.
So, it's a binary search, basically to the T. There is nothing special here. Consequently, we can conclude that the runtime is O(log n).
Comments
Post a Comment