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
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing typos
  • Loading branch information
Muaath5 committed Aug 10, 2023
commit 5818b96ab48d7f067a043c354036cd84fbb1f3c0
7 changes: 3 additions & 4 deletions content/6_Advanced/Parallel_Binary_Search.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ frequency: 0
<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

Let's think about how to use binary to answer single query.
We can see that connvectivity of the nodes is a monotonic function.
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


Now let's use parallel binary search:

First, sort the queries by median.

Then sweep through the array of edges and union them in the DSU,
whenevery there is a query with median = $i$, if the two nodes where connected in DSU, it means the answer is $\leq i$, otherwise it means $\gt i$.
Then sweep through the array of edges and 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$, otherwise it means $\gt i$.

**Complexity:**

Expand Down
55 changes: 55 additions & 0 deletions content/6_Advanced/Parallel_Binary_Search.problems.json.save
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"MODULE_ID": "parallel-binary-search",
"sam": [
{
"uniqueId": "cses-2101",
"name": "New Roads Queries",
"url": "https://cses.fi/problemset/task/2101/",
"source": "CSES",
"difficulty": "Easy",
"isStarred": false,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
"kind": "internal"
}
}
],
"gen": [
{
"uniqueId": "hr-travelInHackerland",
"name": "Travel in Hackerland",
"url": "https://www.hackerrank.com/contests/may-world-codesprint/challenges/travel-in-hackerland",
"source": "HR",
"difficulty": "Easy",
"isStarred": true,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
}
},
{
"uniqueId": "ac-stampRally",
"name": "Stamp Rally",
"url": "https://atcoder.jp/contests/agc002/tasks/agc002_d",
"source": "AC",
"difficulty": "Easy",
"isStarred": false,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
"kind": "autogen-label-from-site",
"site": "AC"
}
},
{
"uniqueId": "coci-20-index",
"name": "2020 - Index",
"url": "https://evaluator.hsin.hr/tasks/HONI202167index/",
"source": "COCI",
"difficulty": "Normal",
"isStarred": false,
"tags": ["PBS", "Segtree"],
"solutionMetadata": {
"kind": "none"
}
}
]
}
68 changes: 68 additions & 0 deletions content/6_Advanced/Parallel_Binary_Search.problems.json.save.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"MODULE_ID": "parallel-binary-search",
"sam": [
{
"uniqueId": "cses-2101",
"name": "New Roads Queries",
"url": "https://cses.fi/problemset/task/2101/",
"source": "CSES",
"difficulty": "Easy",
"isStarred": false,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
"kind": "in-module",
"moduleId": "parallel-binary-search"
}
}
],
"gen": [
{
"uniqueId": "ac-IndependentSet",
"name": "Independent Set",
"url": "{
"uniqueId": "ac-IndependentSet",
"name": "Independent Set",
"url": "https://atcoder.jp/contests/dp/tasks/dp_p",
"source": "AC",
"difficulty": "Easy",
"isStarred": true,
"tags": ["Tree", "DP"],
"solutionMetadata": {
"kind": "internal"
}
}",
"source": "AC",
"difficulty": "Easy",
"isStarred": true,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
"kind": "none"
}
},
{
"uniqueId": "ac-stampRally",
"name": "Stamp Rally",
"url": "https://atcoder.jp/contests/agc002/tasks/agc002_d",
"source": "AC",
"difficulty": "Easy",
"isStarred": false,
"tags": ["PBS", "DSU"],
"solutionMetadata": {
"kind": "autogen-label-from-site",
"site": "AC"
}
},
{
"uniqueId": "coci-20-index",
"name": "2020 - Index",
"url": "https://evaluator.hsin.hr/tasks/HONI202167index/",
"source": "COCI",
"difficulty": "Normal",
"isStarred": false,
"tags": ["PBS", "Segtree"],
"solutionMetadata": {
"kind": "none"
}
}
]
}