en/docs/chapter_divide_and_conquer/binary_search_recur.md
We have already learned that search algorithms are divided into two major categories.
In fact, search algorithms with time complexity of $O(\log n)$ are typically implemented based on the divide and conquer strategy, such as binary search and trees.
The divide and conquer strategy of binary search is as follows.
Divide and conquer can improve search efficiency because brute-force search can only eliminate one option per round, while divide and conquer search can eliminate half of the options per round.
In previous sections, binary search was implemented based on iteration. Now we implement it based on divide and conquer (recursion).
!!! question
Given a sorted array `nums` of length $n$, where all elements are unique, find the element `target`.
From a divide and conquer perspective, we denote the subproblem corresponding to the search interval $[i, j]$ as $f(i, j)$.
Starting from the original problem $f(0, n-1)$, perform binary search through the following steps.
1. and 2. until target is found or the interval is empty and return.The figure below shows the divide and conquer process of binary search for element $6$ in an array.
In the implementation code, we declare a recursive function dfs() to solve the problem $f(i, j)$:
[file]{binary_search_recur}-[class]{}-[func]{binary_search}