pydatastructs icon indicating copy to clipboard operation
pydatastructs copied to clipboard

feat: Implement add_vertex and remove_vertex for AdjacencyMatrix

Open asmit27rai opened this issue 9 months ago • 1 comments

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

asmit27rai avatar Mar 12 '25 18:03 asmit27rai

@czgdp1807 Pls review this PR

asmit27rai avatar Mar 12 '25 18:03 asmit27rai