Skip to content
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

Adding Parallel Binary Search module #3859

Closed
wants to merge 23 commits into from
Closed

Conversation

Muaath5
Copy link

@Muaath5 Muaath5 commented Aug 7, 2023

Place an "x" in the corresponding checkbox if it is done or does not apply to this pull request.

  • I have tested my code.
  • I have added my solution according to the steps here.
  • I have followed the code conventions mentioned here.
    • I understand that if it is clear that I have not attempted to follow these conventions, my PR will be closed.
    • If changes are requested, I will re-request a review after addressing them.
  • I have linked this PR to any issues that it closes (New topic - Parallel Binary Search #3624)

I did this pull request because the previous one was closed by stale (#3777 )

content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
Copy link
Member

@envyaims envyaims left a comment

Choose a reason for hiding this comment

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

looks mostly fine!

content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
Copy link
Member

@envyaims envyaims left a comment

Choose a reason for hiding this comment

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

mighty fine

content/6_Advanced/Parallel_Binary_Search.mdx Outdated Show resolved Hide resolved
Copy link
Member

@jessechoe10 jessechoe10 left a comment

Choose a reason for hiding this comment

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

Please rewrite everything since most of it doesn't really make sense to me right now (a lot of grammatical issues), and the explanations are incomplete and can be more elaborated, especially for someone who doesn't know the topic.

## Tutorial
This technique is usually used when we can solve a single query by doing linear or binary search on monotonic function.

The trick is doing it offline, sort queries by their median (initially $l$, $r$ will be the binary search values), do linear search,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The trick is doing it offline, sort queries by their median (initially $l$, $r$ will be the binary search values), do linear search,
The trick is doing it offline, sorting queries by their median (initially $l$, $r$ will be the binary search values), linearly searching

This technique is usually used when we can solve a single query by doing linear or binary search on monotonic function.

The trick is doing it offline, sort queries by their median (initially $l$, $r$ will be the binary search values), do linear search,
whenever you find a query its median in same as your position in linear search, check the monotonic function, and do same as binary search (edit either $l$ or $r$).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
whenever you find a query its median in same as your position in linear search, check the monotonic function, and do same as binary search (edit either $l$ or $r$).
whenever you find a query its median in same as your position in linear search, checking the monotonic function, and binary searching (edit either $l$ or $r$).

Comment on lines +23 to +24
The trick is doing it offline, sort queries by their median (initially $l$, $r$ will be the binary search values), do linear search,
whenever you find a query its median in same as your position in linear search, check the monotonic function, and do same as binary search (edit either $l$ or $r$).
Copy link
Member

Choose a reason for hiding this comment

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

If that's what you meant, then resolve those changes. If not, then please rewrite that sentence since it doesn't really make sense right now.

The trick is doing it offline, sort queries by their median (initially $l$, $r$ will be the binary search values), do linear search,
whenever you find a query its median in same as your position in linear search, check the monotonic function, and do same as binary search (edit either $l$ or $r$).

You will need to do the linear search $O(\log_2{N})$ times, so $l = r$.
Copy link
Member

Choose a reason for hiding this comment

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

Rewrite this... It sounds weird


You will need to do the linear search $O(\log_2{N})$ times, so $l = r$.

Usually the complexity would be: $O((N+Q) \cdot \log_2{(N+Q)}^2)$
Copy link
Member

Choose a reason for hiding this comment

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

This is an incomplete thought. Usually it's that time complexity but you should also state the time complexity of the parallel binary search following a ", but"

<FocusProblem problem="sam" />

## Solution - New Roads Queries
We can see that connectivity of the nodes is a monotonic function.
Copy link
Member

Choose a reason for hiding this comment

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

How

Comment on lines +33 to +35
We can see that connectivity of the nodes is a monotonic function.

Now let's use parallel binary search:
Copy link
Member

Choose a reason for hiding this comment

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

Combine these sentences in some way


When sweeping through the array of edges, union them in the DSU.

Whenever there is a query with median = $i$, if the two nodes where connected in DSU, it means the answer is $\leq i$ ($r = i$), otherwise it means $\gt i$ ($l = i+1$).
Copy link
Member

Choose a reason for hiding this comment

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

Split this into two sentences since it's too wordy and grammatically incorrect


<FocusProblem problem="sam" />

## Solution - New Roads Queries
Copy link
Member

Choose a reason for hiding this comment

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

Definitely expand on this solution

@stale
Copy link

stale bot commented Aug 21, 2023

This pull request has been automatically marked as stale because it has not had recent activity. Please address the requested changes and re-request reviews. Thank you for your contribution!

@stale stale bot added the stale label Aug 21, 2023
@stale
Copy link

stale bot commented Sep 3, 2023

Changes requested have not been made. Free free to create a new PR.

@stale stale bot closed this Sep 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants