0

I wrote pseudo-code that finds the k'th number in a k rotate-sorted array. A k rotate-sorted array is an array for which A[k]<A[K+1]<...<A[1]<...<A[N]<...<A[K-1].

So in this array:

[3,4,5,6,7,1,2]
k=5

I'm having a hard time proving why my code is correct

find_k'th :
    start=A[1]
    end = A[n]
    while ( A[start]>A[end])
        start=A[floor(start+end)/2]
    return start;
limitless
  • 669
  • 7
  • 18
  • Isn't the `k` simply the position where the ordering changes? – Codor May 13 '16 at 14:43
  • Yes, I thought about this but I didnt convinced myself enough, i guees this is the answer because in the range of the new [start - end] we now have unrotate-sorted array. – limitless May 13 '16 at 15:21

0 Answers0