Skip to content

Conversation

@lens161
Copy link

@lens161 lens161 commented Nov 17, 2025

  • [ x] I have read CONTRIBUTING.md.
  • [ x] This pull request is all my own work -- I have not plagiarized it.
  • [ x] All filenames are in PascalCase.
  • [ x] All functions and variable names follow Java naming conventions.
  • [ x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • [ x] All new code is formatted with clang-format -i --style=file path/to/your/file.java

Summary

This PR adds an implementation of Centroid Decomposition for trees. The algorithm recursively finds centroids of subtrees and builds a centroid tree of height O(log n). It is useful for distance queries and divide-and-conquer algorithms on trees.

Details

Allows adding edges to the original tree.

Builds the centroid decomposition with build().

Provides methods to get centroid parents and children.

Includes a method to visit all centroid ancestors of a node.

Includes JUnit tests.

CI check completed using: mvn clean verify

@codecov-commenter
Copy link

codecov-commenter commented Nov 17, 2025

Codecov Report

❌ Patch coverage is 92.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.51%. Comparing base (5a68ba9) to head (e96043f).
⚠️ Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
.../com/thealgorithms/tree/CentroidDecomposition.java 92.50% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7075      +/-   ##
============================================
+ Coverage     78.33%   78.51%   +0.17%     
- Complexity     6661     6776     +115     
============================================
  Files           752      759       +7     
  Lines         22180    22419     +239     
  Branches       4357     4397      +40     
============================================
+ Hits          17375    17602     +227     
- Misses         4106     4111       +5     
- Partials        699      706       +7     

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

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.

2 participants