You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/num_methods/binary_search.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -142,9 +142,9 @@ This paradigm is widely used in tasks around trees, such as finding lowest commo
142
142
143
143
<small>Note that this section follows the description in[Sports programming in practice](https://kostka.dev/sp/).</small>
144
144
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$) insome 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$) ina sorted 0-indexed array $A$. Naturally, each query can be answered using binary search.
146
146
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]$
148
148
with queries: $X =[8,11,4,5]$. We can use binary search for each query sequentially.
||\( index = 3\)|\( index = 5\)|\( index = 1\)|\( index = 2\)|
163
163
164
-
We generally process this table by columns (queries), but notice that in each row we often repeat access to certain values ofour array. To limit access tothe 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 ofthe array. To limit access tothese 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.
165
165
166
166
```{.cpp file=parallel-binary-search}
167
-
// Computes the index of the largest value intable 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 ina 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) {
169
169
int N = A.size();
170
170
int M = X.size();
171
171
vector<int> left(M, -1);
@@ -192,7 +192,7 @@ vector<int> ParallelBinarySearch(vector<int>& A, vector<int>& X) {