Skip to content

Commit 56e7840

Browse files
committed
Some fixes.
1 parent 994c1f2 commit 56e7840

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/num_methods/binary_search.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ This paradigm is widely used in tasks around trees, such as finding lowest commo
142142

143143
<small>Note that this section follows the description in [Sports programming in practice](https://kostka.dev/sp/).</small>
144144

145-
Imagine that we want to answer $Z$ queries about the index of the largest value less than or equal to some $X_i$ (for $i=1,2,\ldots,Z$) in some sorted 0-indexed array $A$. Naturally, each query can be answered using binary search.
145+
Imagine that we want to answer $Z$ queries about the index of the largest value less than or equal to some $X_i$ (for $i=1,2,\ldots,Z$) in a sorted 0-indexed array $A$. Naturally, each query can be answered using binary search.
146146

147-
Specifally, let us consider the following array $A = [1,3,5,7,9,9,13,15]$
147+
Specifically, let us consider the following array $A = [1,3,5,7,9,9,13,15]$
148148
with queries: $X = [8,11,4,5]$. We can use binary search for each query sequentially.
149149

150150
| query | \( X_1 = 8 \) | \( X_2 = 11 \) | \( X_3 = 4 \) | \( X_4 = 5 \) |
@@ -161,11 +161,11 @@ with queries: $X = [8,11,4,5]$. We can use binary search for each query sequenti
161161
| **step 4** | answer in \([3,4)\) | answer in \([5,6)\) | answer in \([1,2)\) | answer in \([2,3)\) |
162162
| | \( index = 3 \) | \( index = 5 \) | \( index = 1 \) | \( index = 2 \) |
163163

164-
We generally process this table by columns (queries), but notice that in each row we often repeat access to certain values of our array. To limit access to the values, we can process the table by rows (steps). This does not make huge difference in our small example problem (as we can access all elements in $\mathcal{O}(1)$), but in more complex problems, where computing these values is more complicated, this might be essential to solve these problems efficiently. Moreover, note that we can arbitrarily choose the order in which we answer questions in a single row. Let us look at the code implementing this approach.
164+
We generally process this table by columns (queries), but notice that in each row we often repeat access to certain values of the array. To limit access to these values, we can process the table by rows (steps). This does not make huge difference in our small example problem (as we can access all elements in $\mathcal{O}(1)$), but in more complex problems, where computing these values is more complicated, this might be essential to solve these problems efficiently. Moreover, note that we can arbitrarily choose the order in which we answer questions in a single row. Let us look at the code implementing this approach.
165165

166166
```{.cpp file=parallel-binary-search}
167-
// Computes the index of the largest value in table A less than or equal to X_i for all i.
168-
vector<int> ParallelBinarySearch(vector<int>& A, vector<int>& X) {
167+
// Computes the index of the largest value in a sorted array A less than or equal to X_i for all i.
168+
vector<int> parallel_binary_search(vector<int>& A, vector<int>& X) {
169169
int N = A.size();
170170
int M = X.size();
171171
vector<int> left(M, -1);
@@ -192,7 +192,7 @@ vector<int> ParallelBinarySearch(vector<int>& A, vector<int>& X) {
192192
}
193193
}
194194
}
195-
return P;
195+
return left;
196196
}
197197
```
198198

0 commit comments

Comments
 (0)