Reputation: 111
I know that the function is executed ln(N)/ln(K) times;but in average does it make K operations?
Questions:
Furthermore I believe that ternary search is faster;because I made a comparing computer program.
Upvotes: 2
Views: 1170
Reputation: 1
No, because the correct answer is (k - 1) log n / log k + O(1): only k - 1 comparisons (really only lg k + O(1)) are needed to reduce the size of the search range by a factor of k. This can be proved by induction on the recurrence T(1) = 1, T(2) = 2, T(n) = (k - 1) + T(n / k).
The integer argmin of (k - 1) / log k occurs at 2. There are plenty of computer architectural reasons why ternary search might be faster anyway.
Upvotes: 0