Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
amankumar100 wants to merge6 commits intoTheAlgorithms:master
base:master
Choose a base branch
Loading
fromamankumar100:Graph-Tree-Check

Conversation

amankumar100
Copy link

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:

  • Detect cycles
  • Ensure the graph is fully connected

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.

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

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
Copy link

codecov-commenter commentedJun 26, 2025
edited
Loading

Codecov Report

Attention: Patch coverage is0% with33 lines in your changes missing coverage. Please review.

Project coverage is 74.03%. Comparing base(a8ad162) to head(9b35e09).
Report is 1 commits behind head on master.

Files with missing linesPatch %Lines
...in/java/com/thealgorithms/tree/GraphTreeCheck.java0.00%33 Missing⚠️
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.
📢 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.

<description>
Avoid using the main method.
Custom PMD checks for TheAlgorithms/Java
Copy link
Member

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@siriaksiriaksiriak left review comments

@DenizAltunkapanDenizAltunkapanAwaiting requested review from DenizAltunkapanDenizAltunkapan is a code owner

@yanglbmeyanglbmeAwaiting requested review from yanglbmeyanglbme is a code owner

@vil02vil02Awaiting requested review from vil02vil02 is a code owner

@BamaCharanChhandogiBamaCharanChhandogiAwaiting requested review from BamaCharanChhandogiBamaCharanChhandogi is a code owner

@alxkmalxkmAwaiting requested review from alxkmalxkm is a code owner

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@amankumar100@codecov-commenter@siriak

[8]ページ先頭

©2009-2025 Movatter.jp