Skip to content

Implement add_vertex and remove_vertex for Dynamic Graphs in AdjacencyMatrix #634

Open
@asmit27rai

Description

@asmit27rai

Implement add_vertex and remove_vertex for Dynamic Graphs in AdjacencyMatrix

Description

Currently, the AdjacencyMatrix class in pydatastructs only supports static graphs, as indicated by the NotImplementedError in the add_vertex and remove_vertex methods. This limitation restricts the use of the adjacency matrix representation for dynamic graphs where vertices can be added or removed after the graph is initialized.

Expected Behavior

The add_vertex and remove_vertex methods should be implemented to allow dynamic modification of the graph. Specifically:

  1. add_vertex: This method should add a new vertex to the graph and update the adjacency matrix and edge weights accordingly.
  2. remove_vertex: This method should remove a vertex from the graph, along with all edges connected to it, and update the adjacency matrix and edge weights.

Proposed Solution

  1. add_vertex:

    • Add the new vertex to the vertices list.
    • Update the matrix dictionary to include the new vertex as a key with an empty dictionary as its value.
    • Ensure that the new vertex is added as a column in the adjacency matrix for all existing vertices.
  2. remove_vertex:

    • Remove the vertex from the vertices list.
    • Remove the vertex from the matrix dictionary and all its associated edges.
    • Remove any edge weights involving the vertex from the edge_weights dictionary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions