Thursday, June 12, 2008

Binary Search in Circular Sorted Array. How can we search a number in a circularly sorted array?

we can skip half the elements of our array during our search process

the array is not random array but there are two sorted sub-arrays;

1. Calculate mid position of the array.

2. if start element is less than mid element
then first half of array is sorted
Do the Binary search in first half.

3. if mid element is less than end element
then second half of array is sorted
Do Binary Search in second half.

3. Repeat Step1 and Step2 for the unsorted part of array by adjusting start and end pointers respectively.

No comments: