2

I know that the function is executed ln(N)/ln(K) times;but in average does it make K operations?

Questions:

  1. is there any proof that k*ln(N)/ln(K) is the average number of executions?
  2. If this formula is correct, then ternary search will be the fastest search as k/ln(k) will be minimum (for integers) because 3 is the closest integer to "e" (the real minimum) which is very easy to prove using differentiation.

Furthermore I believe that ternary search is faster;because I made a comparing computer program.

svick
  • 214,528
  • 47
  • 357
  • 477
user1205603
  • 91
  • 1
  • 1
  • 4
  • Yes ternary is faster because it is closer to 'e'. However computers are faster at binary. If you were to have a ternary computer you would want 3. – robert king Feb 13 '12 at 11:24
  • The second part of your question is discussed [here](http://stackoverflow.com/questions/3498382/why-use-binary-search-if-theres-ternary-search). – Sergey Kalinichenko Feb 13 '12 at 11:24

1 Answers1

0
  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).

  2. 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.

wat
  • 1