I just wrote this exam, in which there was question: Consider a array of size 2n, where the numbers in odd positions are sorted in ascending order and the the numbers in even positions in descending order. Now, if I have to search for a number in this array, which is a good way to do this? The options were:
- Quick sort and then binary search
- Merge the two sorted arrays and then binary search
- Sequential search
In 1, Quick Sort takes O(n log n) and binary search, O(log n)
In 2, Merge takes O(n) and then O(log n) for binary search
In 3, it takes O(n).
So 3 turns out to be the way to go. Is that correct? Is there a better choice which might not have been given?
EDIT: I accepted Lukas's answer since he was the first. Sigh, that was the other option. I get a -1. :(