search an element in a sorted and rotated array in python





Search an element in a sorted and rotated array is using Binary search method,Find an element in a sorted and rotated array using the binary search method, see how it works,We are using the same concept but different ideas,We will divide the array into 2 sub array and So for instance, 1 2 3 4 5 might become 3 4 5 1 2. Devise a way to find an element in the rotated array

Algo:

  • 1 Find middle point mid in array/list = (l + r)//2

  • 2 If key is present at middle point is equal so the return mid.

  • 3 If key>=arr[l] and key<=arr[mid]
  • a) If key to be searched lies in range from arr[l] to arr[mid], recur for arr[l..mid].
    b) Else recur for arr[mid+1..h]

  • 4 if key>=arr[mid] and key<=arr[r]
  • a) If key to be searched lies in range from arr[mid+1] to arr[h], recur for arr[mid+1..h].
    b) Else recur for arr[l..mid]