Given a bitonic array and element x in the array, find the index of x in 2log(n) time

后端 未结 7 1065
我寻月下人不归
我寻月下人不归 2021-01-29 22:14

First, a bitonic array for this question is defined as one such that for some index K in an array of length N where 0 < K < N - 1 an

7条回答
  •  后悔当初
    2021-01-29 22:50

    Finding the change of sign among the first order differences, by standard dichotomic search, will take 2Lg(n) array accesses.

    You can do slightly better by using the search strategy for the maximum of a unimodal function known as Fibonacci search. After n steps each involving a single lookup, you reduce the interval size by a factor Fn, corresponding to about Log n/Log φ ~ 1.44Lg(n) accesses to find the maximum.

    This marginal gain makes a little more sense when array accesses are instead costly funciton evaluations.

提交回复
热议问题