Re: using a for loop to determine maximum value of an int variable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"Bill Butler" <qwerty@xxxxxxxx> wrote in message
news:tYJdh.114$qh.5@xxxxxxxxxxx
[...]
All good points
Perhaps I should have spent more than 5 minutes on it :^)
I was simply attempting to point out how to improve on O(N) performance

Well, I hope you're not taking it too hard. After all, applying the
unbounded binary search technique the problem seems reasonable, if you want
to completely abstract it. :) Just getting the basic algorithm out there
is the key thing, even if it could use a little massaging after the fact.

And I think you're being way too conservative on your algorithm order
analysis. IMHO, since the element of the data that alters the length of the
algorithm is the number of bits in the variable (rather than the maximum
value per se), I think that the order is actually exponential -- O(2^N) --
rather than linear. So your binary search is clearly even *more* of an
improvement than you seem to think.

Still, hopefully we can all agree that using a built-in constant is really
the fastest, most appropriate solution. :)

Pete


.



Relevant Pages