public static void Main()
int[] sortedList = new int[]{ 2, 5, 6, 9, 23, 54, 55, 66, 71, 113, 203, 1999, 2000};
var outputIndex = TestSearch.IterativeBinarySearch(sortedList, val);
Console.WriteLine(string.Format("Index of value {0} in sortedList is: {1}", val , outputIndex));
outputIndex = TestSearch.RecursiveBinarySearch(sortedList, 0, sortedList.Length - 1, val);
Console.WriteLine(string.Format("Index of value {0} in sortedList is: {1}", val , outputIndex));
public static class TestSearch
public static int IterativeBinarySearch(int[] list, int val){
int high = list.Length - 1;
var mid = (low + high) / 2;
else if(list[mid] > val){
public static int RecursiveBinarySearch(int[] list, int low, int high, int val){
int mid = (low + high) / 2;
return RecursiveBinarySearch(list, mid + 1, high, val);
return RecursiveBinarySearch(list, low, mid - 1, val);