Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56e7840

Browse files
committed
Some fixes.
1 parent994c1f2 commit56e7840

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$) 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.
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 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.
165165

166166
```{.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) {
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-
returnP;
195+
returnleft;
196196
}
197197
```
198198

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp