Java
Java copied to clipboard
Optimize BreadthFirstSearch implementation with bug fixes and improvements
- 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
- [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
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 :warning: |
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
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Hi Please review the pr and merge!