Revise README and enhance graph algorithms for Python 3#1
Open
mebriki wants to merge 6 commits intoyouben11:masterfrom
Open
Revise README and enhance graph algorithms for Python 3#1mebriki wants to merge 6 commits intoyouben11:masterfrom
mebriki wants to merge 6 commits intoyouben11:masterfrom
Conversation
Updated project name and added detailed overview of graph implementations.
* Reworked weighted graph core algorithms for correctness: * Reimplement Kruskal with Union-Find for correct MST construction. * Reimplement Prim with min-heap and disconnected-graph guard. * Reimplemented dijkstra with priority-queue relaxation and correct path reconstruction. * Reimplemented Bellman-Ford with standard relaxation and proper negative-cycle detection. * Weighted graph structure and traversal safety: * Rework unoriented to build a safe undirected adjacency map, including referenced-only nodes. * Replace cycle detection logic with robust traversal over the undirected view. * unweighted graph behavior improvements: * Replace cycle detection with DFS recursion-stack detection (directed-graph correct behavior). * Reimplement bestPath with BFS + parent reconstruction. * Add missing/unreachable guards in bestPath to return empty path safely. * Added concise docstrings and minor readability improvements. * Fix Python 3 compatibility issues (removed dict-keys indexing patterns).
…weighted graph behavior. - Update README.md
…rams: - Weighted sample graph with edge weights - MST output graph (matching Prim/Kruskal expected tree) - Unweighted sample graph (directed) This gives users immediate visual context alongside the code examples and tests.
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.
This pull request modernizes and refines the graph theory codebase, providing clearer structure, robust implementations for key algorithms, and comprehensive testing. The main changes include significant improvements to both the
weighted_graph.pyandunweighted_graph.pymodules, a complete rewrite of the documentation inREADME.md, and the addition of automated tests.Key changes by theme:
Documentation and Project Structure
README.mdto provide a detailed project overview, usage examples, visualization guides, and notes on edge cases and exceptions. The documentation now clearly distinguishes between weighted and unweighted graph modules and explains the test suite.Testing
tests/test_graphs.pywith comprehensive unit tests covering shortest path algorithms, minimum spanning trees (Prim and Kruskal), cycle detection, and edge cases for both weighted and unweighted graphs.Unweighted Graph Improvements (
unweighted_graph.py)isCyclicto use a depth-first search with recursion and stack tracking, making cycle detection for directed graphs more robust and readable.bestPathto use a standard breadth-first search (BFS), improving correctness and clarity for finding the shortest path between nodes.Weighted Graph Improvements (
weighted_graph.py)isCyclicto use an undirected DFS approach, ensuring accurate cycle detection for undirected graphs.General Codebase Enhancements
heapq,deque) and improved code style for readability and maintainability. [1] [2]These updates make the codebase more reliable, easier to use and test, and better suited for both learning and practical experimentation with graph algorithms.