Skip to content

Commit 2044a99

Browse files
committed
add special case to binary search definition
1 parent 7c8dbc1 commit 2044a99

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/num_methods/binary_search.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ $$
7979
f(0) \leq f(1) \leq \dots \leq f(n-1).
8080
$$
8181

82-
The binary search, the way it is described above, finds the partition of the array by the predicate $f(M)$, holding the boolean value of $k < A_M$ expression. In other words, binary search finds the unique index $L$ such that $f(L) = 0$ and $f(R)=f(L+1)=1$.
82+
The binary search, the way it is described above, finds the partition of the array by the predicate $f(M)$, holding the boolean value of $k < A_M$ expression.
83+
In other words, binary search finds the unique index $L$ such that $f(L) = 0$ and $f(R)=f(L+1)=1$, or gives us $L = n-1$ if $f(0) = \dots = f(n-1) = 0$ or $L = -1$ if $f(0) = \dots = f(n-1) = 1$.
8384

8485
It is possible to use arbitrary monotonous predicate instead of $k < A_M$. It is particularly useful when the computation of $f(k)$ is requires too much time to actually compute it for every possible value.
8586

0 commit comments

Comments
 (0)