I came across the following question:
Suppose I modify this sorted list of 4n different numbers as follows:
Keep the elements in even positions (positions 2, 4, 6, ... 4n) as they are. Make up n disjoint pairs (i, j) at odd numbered positions, where i = 2k + 1 for some k = 0 to n-1 and j = 2k + 1 for some k = n to 2n-1.
Now replace the elements at positions i and j for each such pair. (i.e. each element in an odd numbered position in the first half of the array is replaced by some element in an odd numbered position in the second half of the array. No element is involved in more than one swap (i.e., the swaps do not intersect) You do not you know these (i, j) pairs, except that an element in an odd numbered position in the first half of the array exchanges some element in an odd numbered position in the second half. Now, taking into account the element x, explain how you can determine if whether x in (new res hu ffl ed) in O (logn) time.
Honestly, I'm not sure how to approach this. Given x, I can do a search to see if it exists in any even position using binary search. But numbers in odd positions are no longer sorted.
Any help is appreciated. Thank you
source share