Skip to content

On Parallel Binary Search #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

On Parallel Binary Search #1384

wants to merge 15 commits into from

Conversation

Kostero
Copy link
Contributor

@Kostero Kostero commented Oct 27, 2024

No description provided.

@mhayter
Copy link
Contributor

mhayter commented Oct 27, 2024

Hello @Kostero and welcome! Thanks for joining the project and thanks for the contribution!

Here's some quick initial feedback:

Consider putting text in online grammar/spell checker. I noticed than 'Specifically' was misspelled.

Also, I'd personally prefer more descriptive variable names rather than A, X, M, etc. especially consider M is already used in the article for midpoint.

Also, consider compiling the given code.

What is P that is returned?

Also, I think we use snake case for functions and it may make sense to have left and right be a struct as they are parallel arrays.

@Kostero
Copy link
Contributor Author

Kostero commented Oct 27, 2024

Thanks for the feedback.

I have fixed some issues. Comments for the remaining ones below.

Also, I'd personally prefer more descriptive variable names rather than A, X, M, etc. especially consider M is already used in the article for midpoint.

A and X are mostly there to keep things simple and to not repeat long variables names (especially in the table explaining what we actually do). I would prefer to keep it that way.

What is P that is returned?

I have a problem of changing the variables over and over, after doing all the checks (including compilation). It should work now. I will try to add tests in the follow-up, just wanted to get the first review asap.

It may make sense to have left and right be a struct as they are parallel arrays.

I kinda disagree here, as they directly refer to int l = -1, r = n; in the prior binary search code (I changed the variable names now to be more consistent), so I would keep them as separate parallel arrays (as they are separate parallel variables in that code).

Copy link
Member

@adamant-pwn adamant-pwn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! I have a few comments that I think should be addressed before this is merged.

| **step 4** | answer in \([3,4)\) | answer in \([5,6)\) | answer in \([1,2)\) | answer in \([2,3)\) |
| | \( index = 3 \) | \( index = 5 \) | \( index = 1 \) | \( index = 2 \) |

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really prefer to add a bit more of the following:

  1. Motivation to ever consider doing it in the first place;
  2. Some specific examples on how using this reduces the complexity.

I think for the latter there are some very simple applications like finding order of key on segment in $O(\log n)$?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL now

@mhayter
Copy link
Contributor

mhayter commented Apr 10, 2025

Any update here?

@mhayter
Copy link
Contributor

mhayter commented Jun 28, 2025

Is this dead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parallel Binary Search
3 participants