About 2,450,000 results
Open links in new tab
  1. algorithm - Binary Search in Array - Stack Overflow

    Oct 30, 2008 · You can do it recursively (easiest) or iteratively. Time complexity of a binary search is O(log N) which is considerably faster than a linear search of checking each element at O(N). Here are some examples from Wikipedia: Binary Search Algorithm: Recursive:

  2. c - Optimize Binary Search Algorithm - Stack Overflow

    From the Binary Search Algorithm article on Wikipedia: About half the time, the first test will be true so that there will be only one comparison of a and b, but the other half of the time it will be false, and a second comparison forced.

  3. Binary Search in Javascript - Stack Overflow

    Now, say that you make both the linear search algorithm 25% faster and the binary search algorithm 25% faster. Now, k is 0.75 for both algorithms. The complexity of the linear search decreases to O(384) (a gain of 128 performance points), whereas the binary search decreases to O(7.5) (a gain of only 2.5 performance points). This minimal gain ...

  4. big o - Binary search - worst/avg case - Stack Overflow

    Apr 30, 2015 · Or, if the search key is greater,then the algorithm repeats its action on the sub-array to the right. If the remaining array to be searched is empty, then the key cannot be found in the array and a special "not found" indication is returned. So, a binary search is a dichotomic divide and conquer search algorithm. Thereby it takes logarithmic ...

  5. algorithm - Binary Search in 2D Array - Stack Overflow

    Now you have 1D array. Sort it in usual way. And now you can search in it using simple binary search algorithm. Or you can transform your sorted array back to 2D array using this formula: for i:=0 to N*M-1 do A[i div N][i - (i div N)*N]:= T[i]; And use two binary searches:

  6. algorithm - Why to consider binary search running time …

    The way binary search works is by halving the search space of the array and gradually focusing on the matching element. Let's say the size of array is n. Then, in m operations of halving the search space, the size of the array search space becomes n/2^m. When it becomes 1, we have found our element. So equate it to 1 and solve for m.

  7. Excel Find Speed vs. VBA binary Search? - Stack Overflow

    Dec 7, 2009 · Thank you. Doing a test case of searching for 1000 examples inside 52000 possibilities (single sheet), I got 17 seconds for Excel Find vs. 5.5 seconds for the Binary Search. The rub is the binary search failed 25% of the time. I think the problem is excel's sort for strings is ordering differently than VBA's ">" and "<" comparisons. –

  8. How can we prove by induction that binary search is correct?

    Dec 4, 2012 · binary_search works for a range of size zero: Proof: If the range contains no elements, then n==0 and the function returns None, which is correct. Assuming binary_search works for a range of elements of any size from 0 to n, then binary search works for a range of elements of size n+1. Proof:

  9. algorithm - Which is faster, Hash lookup or Binary search ... - Stack ...

    Hash algorithms are O(1) while binary search is O(log n). So as n approaches infinity, hash performance improves relative to binary search. Your mileage will vary depending on n, your hash implementation, and your binary search implementation. Interesting discussion on O(1). Paraphrased: O(1) doesn't mean instantaneous.

  10. algorithm - Generic Binary Search in C# - Stack Overflow

    Oct 19, 2010 · A binary search requires that the input be sorted. How is "b, a, ab, abc, c" sorted? It does not appear to be sorted on any obvious sort key. If you are trying to search unsorted data you should be using a hash set, not a binary search on a list. Also, your calculation of midpoint is subtly wrong because the addition of high + low can overflow.

Refresh