feat(graph): add DSU-based account merge algorithm#7377
feat(graph): add DSU-based account merge algorithm#7377nickzerjeski wants to merge 5 commits intoTheAlgorithms:masterfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7377 +/- ##
============================================
+ Coverage 79.50% 79.53% +0.03%
- Complexity 7161 7175 +14
============================================
Files 797 798 +1
Lines 23409 23467 +58
Branches 4603 4617 +14
============================================
+ Hits 18611 18665 +54
- Misses 4054 4055 +1
- Partials 744 747 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a Disjoint Set Union (Union-Find) based solution for the “merge accounts by shared email” problem under com.thealgorithms.graph, along with JUnit tests. The PR also introduces a new geometry utility for 2D line segment intersection (with tests) and extends binary search test coverage for null inputs.
Changes:
- Added
AccountMerge.mergeAccounts(...)implementing account merging via DSU (path compression + union by rank). - Added
AccountMergeTestcovering shared-email merges, same-name/no-shared-email separation, and empty input. - Added
LineIntersection+LineIntersectionTest, and extendedIterativeBinarySearchTestfor null array/key cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/java/com/thealgorithms/graph/AccountMerge.java |
New DSU-based account merging implementation. |
src/test/java/com/thealgorithms/graph/AccountMergeTest.java |
Tests for account merging behavior and ordering. |
src/main/java/com/thealgorithms/geometry/LineIntersection.java |
New geometry utility for segment intersection + intersection point computation. |
src/test/java/com/thealgorithms/geometry/LineIntersectionTest.java |
Tests for segment intersection and computed intersection point. |
src/test/java/com/thealgorithms/searches/IterativeBinarySearchTest.java |
Added tests for null array and null key behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
7f0c002 to
dbc9534
Compare
|
@nickzerjeski why did you choose the graphs package for this type of algorithm? Could you please look up whether there is a better option? |
|
@DenizAltunkapan I placed AccountMerge in com.thealgorithms.graph because this is fundamentally a connectivity/components problem on an implicit graph (emails/accounts), while Union-Find is the implementation technique. Also, issue #6831 requested adding this in the Graph section. But if you prefer a different organization, I can move it. |
Description
Add an account merge implementation using Disjoint Set Union (Union-Find).
Fixes #6831
Changes
AccountMerge.mergeAccounts(List<List<String>>)incom.thealgorithms.graph.Validation
mvn -q -Dtest=AccountMergeTest test