Skip to content

Conversation

@Nishantrana1
Copy link

-This pull request refactors the vertex addition logic in the adjacency-matrix graph implementation to improve readability, correctness, and maintainability, without changing the external behavior of the code.

Fixes #8

Detailed Changes

1.Reordered adjacency matrix initialization logic

.The creation of a new zero-initialized row for the adjacency matrix is now clearly separated from vertex registration.

.This makes the flow easier to understand:

1.Add vertex

2.Resize matrix

3.Assign index

  1. Improved code clarity

.Initialization logic is now explicit and follows a logical sequence.

.The refactor makes it easier for new contributors to understand how the adjacency matrix grows when a vertex is added.

3.Converted class variables to instance variables

.Moved vertices, edges, and edge_indices into init.

.This prevents shared state between multiple Graph instances and aligns with Python best practices.

4.No functional changes

.Graph behavior, edge addition, and output remain unchanged.

.The refactor is purely structural and readability-focused.

Why this change is important

..Improves comprehension for beginners and reviewers

..Prevents hidden bugs caused by shared class state

..Aligns implementation with standard data structure design patterns

..Makes the project more maintainable and contributor-friendly

🧾 Example “Before vs After” (conceptual)

Before

..Vertex addition

..Matrix expansion

..Row initialization mixed together

After

..Vertex registration

..Matrix expansion

..Explicit zero-initialization

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.

Can you consider change the code of "graph_adjacency-matrix.py" a little?

1 participant