fastest way to determine if an element is in a sorted array
I have an array of sorted ints with a 1,000 or more values (could be up to 5000+). I need to write a function that receives an int and returns a bool based on the element being in the array. I know I can write a for loop with a break, I know I can use jquery .InArray. What would be the best way to implement this, KNOWING that the array is sorted. Thanks. Knowing that the array is sorted a binary search would be the best approach. I think you'd want to use a binary search routine. A binary search routine is whereas a linear search is, on average, . There are many variations to choose form. Here