pydatastructs
pydatastructs copied to clipboard
feat: Implement add_vertex and remove_vertex for AdjacencyMatrix
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_vertexMethod:- Adds a new vertex to the
verticeslist. - 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).
- Adds a new vertex to the
-
remove_vertexMethod:- Removes the vertex from the
verticeslist. - Removes the corresponding row and column from the adjacency matrix.
- Removes all edges connected to the vertex from the
edge_weightsdictionary.
- Removes the vertex from the
-
Tests:
- Added test cases to verify the functionality of
add_vertexandremove_vertex. - Ensured that the adjacency matrix and edge weights are updated correctly.
- Added test cases to verify the functionality of
Fixes : #634
@czgdp1807 Pls review this PR