Search code examples
algorithmdivide-and-conquer

Find the least element in an array, which has a pattern


An array is given such that its element's value increases from 0th index through some (k-1) index. At k the value is minimum, and than it starts increasing again through the nth element. Find the minimum element.

Essentially, its one sorted list appended to another; example: (1, 2, 3, 4, 0, 1, 2, 3).

I have tried all sorts of algorithm like buliding min-heap, quick select or just plain traversing. But cant get it below O(n). But there is a pattern in this array, something that suggest binary search kind of thing should be possible, and complexity should be something like O(log n), but cant find anything. Thoughts ??

Thanks


Solution

  • No The drop can be anywhere, there is no structure to this.

    Consider the extremes

    1234567890
    9012345678
    1234056789
    1357024689
    

    It reduces to finding the minimum element.