Skip to content

feat(graph): add DSU-based account merge algorithm#7377

Open
nickzerjeski wants to merge 5 commits intoTheAlgorithms:masterfrom
nickzerjeski:feat-graph-account-merge-dsu-6831
Open

feat(graph): add DSU-based account merge algorithm#7377
nickzerjeski wants to merge 5 commits intoTheAlgorithms:masterfrom
nickzerjeski:feat-graph-account-merge-dsu-6831

Conversation

@nickzerjeski
Copy link
Copy Markdown
Contributor

Description

Add an account merge implementation using Disjoint Set Union (Union-Find).

Fixes #6831

Changes

  • Added AccountMerge.mergeAccounts(List<List<String>>) in com.thealgorithms.graph.
  • Uses path compression + union by rank to merge accounts sharing at least one email.
  • Added tests for:
    • merging shared-email accounts
    • same-name accounts without shared email staying separate
    • empty input

Validation

  • mvn -q -Dtest=AccountMergeTest test

Copilot AI review requested due to automatic review settings April 13, 2026 08:41
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 94.82759% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.53%. Comparing base (79bc620) to head (b9e1672).

Files with missing lines Patch % Lines
...ain/java/com/thealgorithms/graph/AccountMerge.java 94.82% 1 Missing and 2 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 AccountMergeTest covering shared-email merges, same-name/no-shared-email separation, and empty input.
  • Added LineIntersection + LineIntersectionTest, and extended IterativeBinarySearchTest for 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.

@nickzerjeski nickzerjeski force-pushed the feat-graph-account-merge-dsu-6831 branch from 7f0c002 to dbc9534 Compare April 13, 2026 09:09
@DenizAltunkapan
Copy link
Copy Markdown
Member

@nickzerjeski why did you choose the graphs package for this type of algorithm? Could you please look up whether there is a better option?

@nickzerjeski
Copy link
Copy Markdown
Contributor Author

@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.

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.

[FEATURE REQUEST] Add Disjoint Set (Union-Find) Implementation and Account Merge Problem in Graph Section

4 participants