not work for this case {1,3,2,1}
- posted 4 years ago
@li4dro
|
Suppose you are given a bitonic array. How will you determines whether a given integer is in the array or not?
not work for this case {1,3,2,1}
- posted 4 years ago
@li4dro
|
A bitonic array is comprised of an increasing sequence of integers followed immediately by a decreasing sequence of integers. To perform a search operation in a bitonic array :
For simplicity, let us assume that the array has distinct integers. So the element we are looking for will be either at the increasing or decreasing part of the array. Number of comparisons to find the largest element, in the worst case = logn Number of comparisons to find the element in the increasing part of the array = \( logn_1 \) Number of comparisons to find the element in the decreasing part of the array = \( logn_2 \) where \( n_1+n_2 = n \) = number of elements in the array Therefore, total number of comparisons = 3logn public static int findMax (int[] array, int low, int high){ |