4

Why do we call binary search as 'Divide' and 'Conquer' strategy? It does not combine the results unlike other Divide and Conquer strategies.

3 Answers3

9

This might seem silly but here we go.

Let our array be $A$ and the current range we are searching in be denoted as $[L,R]$ and let $mid = \frac{L+R}{2}$.

  • The divide step - We divide our search space into two ranges - $[L,mid-1]$ and $[mid,R]$.
  • The conquer step - Let's assume that WLOG the element $x$ that we are searching for is such that $x < A[mid]$. Then we combine the knowledge that $x$ can be in $[L,mid)$ and $x$ cannot be in $[mid,R]$ to reduce our search space to $[L',R'] = [L,mid-1]$
Banach Tarski
  • 1,208
  • 9
  • 20
5

There is no accepted formal definition of the divide and conquer paradigm (see this question for some suggestions), and so we must regard this paradigm as an informal concept. The main idea in divide and conquer is to split the original problem into smaller subproblems of a similar nature, and then combine them to deduce the final answer. In the case of binary search (or of quickselect), we split the original problem into one smaller subproblem. In other cases the number of subproblems is larger than two, for example Strassen's fast matrix multiplication algorithm, which splits into 7 subproblems.

Since divide and conquer is an informal concept, it is possible to disagree about what counts as divide and conquer. Describing binary search as divide and conquer is supposed to help you conceptualize the algorithms that you learn in the course. If you don't find this helpful in this case, just ignore it.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
1

We do combine results with binary search. Each recursive call can return either a found location, or it can return None. This None value is the identity element for the combination operator ++, defined such that

result ++ None == result
None ++ result == result
(None ++ None == None, implied by the preceding)

(result can be a simple Yes, or it can be the position where the key was found.)

The key benefit of binary search on sorted data is that one of the two recursive searches is guaranteed to return None, and that one is guaranteed to do so in O(1) time. This means that for our search operation defined as

bs(A, x, x, key) = either result or None
bs(A, x, y, key) = bs(A, x, mid, key) ++ bs(A, mid, y, key)

the running time is defined by T(n) = T(n/2) + O(1) + O(1) = O(lg n), not T(n) = 2*T(n/2) + O(1) = O(n).

In practice, we are less precise and simply say that each call to bs only makes a single recursive call, ignoring what the unmade call would return. We do this to avoid the overhead of making an actual function call whose return value we can predict.

chepner
  • 229
  • 1
  • 5