Skip to content

Documentation - Typo Correction #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Easy-Book/chapters/chapter_decrease_and_conquer.tex
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ \section{Binary Search}
This is the most basic application of binary search. We can set two pointers, \texttt{l} and \texttt{r}, which points to the first and last position, respectively. Each time we compute the middle position \texttt{m = (l+r)//2}, and check if the item $num[m]$ is equal to the target \texttt{t}.
\begin{itemize}
\item If it equals, target found and return the position.
\item If it is smaller than the target, move to the left half by setting the right pointer to the position right before the middle position, $r = m - 1$.
\item If it is larger than the target, move to the right half by setting the left pointer to the position right after the middle position, $l = m + 1$.
\item If it is smaller than the target, move to the right half by setting the left pointer to the position right after the middle position, $l = m + 1$.
\item If it is larger than the target, move to the left half by setting the right pointer to the position right before the middle position, $l = m - 1$.
\end{itemize}
Repeat the process until we find the target or we have searched the whole space. The criterion of finishing the whole space is when \texttt{l} starts to be larger than $r$. Therefore, in the implementation we use a \texttt{while} loop with condition \texttt{l$\leq$ r} to make sure we only scan once of the searching space. The process of applying binary search on our exemplary array is depicted in Fig.~\ref{fig:binary_search_eg_1} and the Python code is given as:
\begin{lstlisting}[language=Python]
Expand Down