Binary search modification for "swaped" array
General Advise


Your methods are difficult to read because you chose to use predominantly single character variable names. Multi-character descriptive variable names are much easier to associate with a value, making the code magnitudes easier to read &amp; maintain. Also, when implementing a binary search it is typical to use hi, lo &amp; mid as variable names.
Whenever you nest a ternary statements, this should be an immediate red flag, that you are not writing clear &amp; maintainable code. As soon as you write a nested ternary statement I would advise you to pause, and consider what functionality you are trying to achieve and consider different ways to express that functionality. I'm not going to say that nested ternary statements are always a sign that your doing something wrong, but nested ternary statements is always a sign you should stop and think about what your doing.


Algorithmic Advise

I am assuming the algorithm is locating the largest element in a semi-sorted array that has two (and only two) distinctly sorted sequences with a pivot index contains largest value in the array.


The three conditions in your switch case are, generally doing the same thing. Each case is returning the largest element in a the array, but can't use the loop because the array is too small. We can cover these conditions in the final return.
You should also check for general error cases such as null or the empty set (new int[0]) being passed into the function.
Since the logic for checking if the current value of the binary search is the pivot index contains a lot of logic to do correctly, I would create a method isPivotIndex().


Putting all that together, your solution could look something like this.

Java Code: (ideone example link)

int findLargestValueInSemiSortedArray(int arr[]) {
  if(arr==null || arr.length==0)
    throw new IllegalArgumentException();

  int hi  = arr.length; /* exclusive upper bound */
  int low = 0;          /* inclusive lower bound */
  int mid;
  while(low &lt; hi) {
    mid  = low/2 + hi/2;
    if(isPivotIndex(arr,mid))
      return arr[mid];
    if(arr[hi-1] &lt; arr[mid])
      low = mid + 1;
    else
      hi  = mid;
  }
  /* Array was actually sorted, either ascending or descending    */
  /* Note that return this covers corner cases of arr.length &lt;= 3 */
  return max(arr[0], arr[arr.length-1]); 
}

int max(final int a, final int b) {
  return (a &gt; b) ? a : b;
}

boolean isPivotIndex(final int[] arr, final int index) {
  int b = arr[index];
  int a = (index &gt; 0) ?            arr[index-1] : Integer.MAX_VALUE;
  int c = (index &lt; arr.length-1) ? arr[index+1] : Integer.MAX_VALUE;
  return a &lt;= b &amp;&amp; b &gt; c;
}


The above is much more readable, has fewer lines of code, and is easier to check for correctness. 


It immediately throws an exception on invalid input. 
It uses isPivotIndex() method to isolate complex logic &amp; maintain a single level of abstraction.
It uses a clever final return to handle corner cases.




Let's consider how the final return covers the corner cases in your original switch statement.

Case 1: (arr.length == 1)


max(arr[0],arr[arr.length-1]) will compare the same values and return arr[0].


Case 2: (arr.length == 2)


max(arr[0],arr[arr.length-1]) will evaluate exactly the same as your ternary statement.


Case 3: (arr.length == 3)


max(arr[0],arr[arr.length-1]) will return the larger of arr[0] and arr[2]. If arr[1] happened to be the max value it would have been the pivot index in the binary search loop and the method would have already returned.