- Notifications
You must be signed in to change notification settings - Fork20k
Graph tree check#6318
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Graph tree check#6318
Conversation
Added a Java program to check if an undirected graph is a tree using DFS and adjacency matrix. Verifies connectivity and absence of cycles.
codecov-commenter commentedJun 26, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## master #6318 +/- ##============================================- Coverage 74.17% 74.03% -0.15% Complexity 5362 5362 ============================================ Files 678 679 +1 Lines 18686 18719 +33 Branches 3625 3636 +11 ============================================- Hits 13860 13858 -2- Misses 4272 4306 +34- Partials 554 555 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
<description> | ||
Avoid using the main method. | ||
Custom PMD checks for TheAlgorithms/Java |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please revert changes to configuration files and make sure your code passes checks and there are JUnit tests
Add Graph Tree Check using DFS and Adjacency Matrix
This PR adds a Java implementation to check whether a given undirected graph is a tree. It uses an adjacency matrix as input and applies Depth-First Search (DFS) to:
Key Points:
Input: number of nodes and adjacency matrix (1 → edge exists, 0 → no edge)
No self-loops allowed
Graph is a tree if:
No cycles exist
All nodes are reachable (i.e., graph is connected)
DSA Concept:
This problem falls under Graph Algorithms and uses DFS traversal for verification.
clang-format -i --style=file path/to/your/file.java