Skip to content

Commit c61ffc1

Browse files
authored
Merge pull request #1404 from konstantinosalatzas/main
Fix typos in binary_search.md, bit-manipulation.md
2 parents 7397078 + 82011c4 commit c61ffc1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/algebra/bit-manipulation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ We can see that the all the columns except the leftmost have $4$ (i.e. $2^2$) se
207207
With the new knowledge in hand we can come up with the following algorithm:
208208
209209
- Find the highest power of $2$ that is lesser than or equal to the given number. Let this number be $x$.
210-
- Calculate the number of set bits from $1$ to $2^x - 1$ by using the formua $x \cdot 2^{x-1}$.
210+
- Calculate the number of set bits from $1$ to $2^x - 1$ by using the formula $x \cdot 2^{x-1}$.
211211
- Count the no. of set bits in the most significant bit from $2^x$ to $n$ and add it.
212212
- Subtract $2^x$ from $n$ and repeat the above steps using the new $n$.
213213

src/num_methods/binary_search.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ f(0) \leq f(1) \leq \dots \leq f(n-1).
8282
$$
8383

8484
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.
85-
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.
85+
It is possible to use arbitrary monotonous predicate instead of $k < A_M$. It is particularly useful when the computation of $f(k)$ requires too much time to actually compute it for every possible value.
8686
In other words, binary search finds the unique index $L$ such that $f(L) = 0$ and $f(R)=f(L+1)=1$ if such a _transition point_ exists, 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$.
8787

88-
Proof of correctness supposing a transition point exists, that is $f(0)=0$ and $f(n-1)=1$: The implementation maintaints the _loop invariant_ $f(l)=0, f(r)=1$. When $r - l > 1$, the choice of $m$ means $r-l$ will always decrease. The loop terminates when $r - l = 1$, giving us our desired transition point.
88+
Proof of correctness supposing a transition point exists, that is $f(0)=0$ and $f(n-1)=1$: The implementation maintains the _loop invariant_ $f(l)=0, f(r)=1$. When $r - l > 1$, the choice of $m$ means $r-l$ will always decrease. The loop terminates when $r - l = 1$, giving us our desired transition point.
8989

9090
```cpp
9191
... // f(i) is a boolean function such that f(0) <= ... <= f(n-1)

0 commit comments

Comments
 (0)