Skip to content
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

feat: Implement add_vertex and remove_vertex for AdjacencyMatrix #640

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

asmit27rai
Copy link

Description

This PR implements the add_vertex and remove_vertex methods for the AdjacencyMatrix class, enabling support for dynamic graphs. Previously, the adjacency matrix implementation only supported static graphs, as indicated by the NotImplementedError in these methods. This enhancement allows users to add or remove vertices after the graph is initialized, making the adjacency matrix representation more versatile.

Changes

  • add_vertex Method:

    • Adds a new vertex to the vertices list.
    • Initializes a new row and column in the adjacency matrix for the new vertex.
    • Sets all entries in the new row and column to False (indicating no edges initially).
  • remove_vertex Method:

    • Removes the vertex from the vertices list.
    • Removes the corresponding row and column from the adjacency matrix.
    • Removes all edges connected to the vertex from the edge_weights dictionary.
  • Tests:

    • Added test cases to verify the functionality of add_vertex and remove_vertex.
    • Ensured that the adjacency matrix and edge weights are updated correctly.

Fixes : #634

- Added `add_vertex` method to dynamically add vertices to the graph.
- Added `remove_vertex` method to dynamically remove vertices and associated edges.
- Updated adjacency matrix and edge weights accordingly.
- Added test cases to verify the new functionality.
@asmit27rai
Copy link
Author

@czgdp1807 Pls review this PR

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.

Implement add_vertex and remove_vertex for Dynamic Graphs in AdjacencyMatrix
1 participant