Faster than binary search for ordered list

后端 未结 11 1718
自闭症患者
自闭症患者 2020-12-12 13:51

is there an algorithm that is faster than binary search, for searching in sorted values of array?

in my case, I have a sorted values (could be any type values) in an

11条回答
  •  时光说笑
    2020-12-12 14:01

    One possibility is to treat it like finding the roots of a function. Basically, finding:

    a[i] <= i <= a[i + 1]
    

    Is equivalent to:

    a[i] - i <= 0 <= a[i + 1] - i
    

    Then you could try something like Newton's method and so on. These kinds of algorithms frequently converge faster than a binary search when they work, but I don't know of one that is guaranteed to converge for all input.

    http://en.wikipedia.org/wiki/Root-finding_algorithm

提交回复
热议问题