Skip to content

Optimize BreadthFirstSearch implementation with bug fixes and improvements #5882

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 22, 2024

Conversation

manishraj27
Copy link
Contributor

  • Fix potential infinite loop by adding cycle detection using HashSet
  • Optimize visited node lookups from O(n) to O(1) using HashSet
  • Clear previous search results for multiple search support
  • Add defensive copying in getVisited() to prevent external state modification
  • Improve code organization and documentation
  • Add consistent node visitation handling
  • Fix root node visitation order inconsistency
  • Prevent redundant node processing
  • I have read CONTRIBUTING.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 with clang-format -i --style=file path/to/your/file.java

…ments

- Fix potential infinite loop by adding cycle detection using HashSet
- Add null value and null node handling for better robustness
- Optimize visited node lookups from O(n) to O(1) using HashSet
- Clear previous search results for multiple search support
- Add defensive copying in getVisited() to prevent external state modification
- Improve code organization and documentation
- Add consistent node visitation handling
- Fix root node visitation order inconsistency
- Prevent redundant node processing
@codecov-commenter
Copy link

codecov-commenter commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.

Project coverage is 66.96%. Comparing base (0bb22fb) to head (8670616).

Files with missing lines Patch % Lines
...com/thealgorithms/searches/BreadthFirstSearch.java 76.92% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5882      +/-   ##
============================================
- Coverage     66.98%   66.96%   -0.02%     
  Complexity     4522     4522              
============================================
  Files           613      613              
  Lines         16985    16990       +5     
  Branches       3281     3282       +1     
============================================
  Hits          11378    11378              
- Misses         5159     5161       +2     
- Partials        448      451       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@manishraj27
Copy link
Contributor Author

Hi Please review the pr and merge!

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak enabled auto-merge (squash) October 22, 2024 18:02
@siriak siriak merged commit 5a1f681 into TheAlgorithms:master Oct 22, 2024
6 checks passed
@manishraj27 manishraj27 deleted the patch-2 branch October 22, 2024 18:11
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.

3 participants