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

后端 未结 7 1067
我寻月下人不归
我寻月下人不归 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:38

    Answers those provided have time complexity of (N/2)*logN. Because the worst case may include too many sub-searches which are unnecessary. A modification is to compare the target value with the left and right element of sub series before searching. If target value is not between two ends of the monotonic series or less than both ends of the bitonic series, subsequent search is redundant. This modification leads to 2lgN complexity.

提交回复
热议问题