zlacker

[parent] [thread] 2 comments
1. gpdere+(OP)[view] [source] 2019-11-11 16:50:41
Oh, agree that for arbitrary large or non integer inputs it might not work. But elsethread jepler has shown a solution off Hacker's Delight which which simply multiplies the index of the most significant bit with a magic constant.
replies(2): >>Mauran+Lr >>slavik+Lt
2. Mauran+Lr[view] [source] 2019-11-11 19:32:33
>>gpdere+(OP)
> But elsethread jepler has shown a solution off Hacker's Delight which which simply multiplies the index of the most significant bit with a magic constant.

...and then checks for and corrects the potential off-by-one thus incurred.

3. slavik+Lt[view] [source] 2019-11-11 19:46:47
>>gpdere+(OP)
When N is fixed, all algorithms become O(1). That's why they appear the same.

If you do these calculations by hand, the complexity will be more obvious because each operation will be smaller.

[go to top]