Why use binary search if there's ternary search?

前端 未结 15 1697
别跟我提以往
别跟我提以往 2020-12-02 12:43

I recently heard about ternary search in which we divide an array into 3 parts and compare. Here there will be two comparisons but it reduces the array to n/3. Why don\'t p

15条回答
  •  半阙折子戏
    2020-12-02 13:02

    Actually, people do use k-ary trees for arbitrary k.

    This is, however, a tradeoff.

    To find an element in a k-ary tree, you need around k*ln(N)/ln(k) operations (remember the change-of-base formula). The larger your k is, the more overall operations you need.

    The logical extension of what you are saying is "why don't people use an N-ary tree for N data elements?". Which, of course, would be an array.

提交回复
热议问题