Repository navigation
[R45-T014] Add traversal invariant checks for BipartiteGraphDFS - #55
Open
shyamlibakale1001-alt wants to merge 1 commit into
Open
shyamlibakale1001-alt wants to merge 1 commit into
shyamlibakale1001-alt wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Documents the DFS coloring and cycle-termination invariant in
src/main/java/com/thealgorithms/datastructures/graphs/BipartiteGraphDFS.java, adds JUnit invariant/property tests (BipartiteGraphDFSInvariantTest.java), and adds a focused runner (work/R45-T014/check.py) that executes the checks and records results and tool versions. All existing behavior and public interfaces are preserved.Related Issue
Fixes: #14
Type of Change
Changes Made
BipartiteGraphDFS.bipartite(lines 41–43) andBipartiteGraphDFS.isBipartite(lines 71–73) insrc/main/java/com/thealgorithms/datastructures/graphs/BipartiteGraphDFS.java: every reachable vertex transitions from-1to{0, 1}once before recursion, ensuring reachable nodes are expanded at most once and cycles terminate without infinite walks. No executable code or public API was modified.src/test/java/com/thealgorithms/datastructures/graphs/BipartiteGraphDFSInvariantTest.javawith 3 test methods:A→B, B→C, C→Aand isolatedD, both directed and undirected): verifies that starting atAexpands[0, 1, 2]once each, terminates withfalse, and never visitsD(D_visits=0).v=1, self-loop0→0→false, visited[0]) and smallest bipartite even cycle with isolated node (0-1-2-3-0, isolated4→true, every node expanded once).FIXED_SEED = 20261111L, 120 bounded valid graphs withvin[1..12]): asserts at-most-once vertex expansion (expansionCounts[node] <= 1, and== 1when bipartite), no input mutation, and 100% agreement with an independent BFS two-coloring oracle (59bipartite,61non-bipartite).work/R45-T014/check.py(with evidence files inwork/R45-T014/), runningmvn testforBipartiteGraphDFSInvariantTest, enforcing a nonzero test count, savingcomparisons.txt,result.txt,mvn_output.txt, andtool_versions.txt, and exiting non-zero on failure.Screenshots / Recordings
Not applicable (no UI changes).
Testing
Command:
python3 work/R45-T014/check.py(runs
mvn -B test -Dtest=BipartiteGraphDFSInvariantTest -Dsurefire.failIfNoSpecifiedTests=false)Result:
tests=3 failures/errors=0 skipped=0 records=5 mvn_exit=0,status=PASSExisting suite:
mvn -B test -Dtest=BipartiteGraphDFSTest -Dsurefire.failIfNoSpecifiedTests=false→Tests run: 6, Failures: 0, Errors: 0, Skipped: 0(BUILD SUCCESS).Negative check: temporarily breaking the unvisited guard on line 56 (
if (color[it] == -1)→if (color[it] != color[node])) causedpython3 work/R45-T014/check.pyto printstatus=FAIL(tests=3 failures/errors=3 skipped=0 mvn_exit=1) and exit non-zero; reverted and re-verified.Style:
mvn -B checkstyle:checkreports0 Checkstyle violations(BUILD SUCCESS).Tool versions and check records are saved in
work/R45-T014/tool_versions.txtandwork/R45-T014/comparisons.txt.Checklist
Additional Notes
Why the invariant holds:
color[it]is assigned1 - color[node](in{0, 1}) before recursing onit, andcolorentries are never reset to-1. Thereforebipartitecan recurse into any reachable vertex at most once, bounding total recursive calls to at mostveven in the presence of arbitrary cycles.The
work/R45-T014/evidence folder is for coursework review only and should not go into any later upstream PR.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 algorithms include a corresponding test class that validates their functionality.
All new code is formatted with
clang-format -i --style=file path/to/your/file.java