Why use binary search if there's ternary search?

前端 未结 15 1675
别跟我提以往
别跟我提以往 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:05

    A ternary search will still give you the same asymptotic complexity O(log N) search time, and adds complexity to the implementation.

    The same argument can be said for why you would not want a quad search or any other higher order.

提交回复
热议问题