Skip to content

Implement add_vertex and remove_vertex for Dynamic Graphs in AdjacencyMatrix #634

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

Open
asmit27rai opened this issue Mar 12, 2025 · 1 comment · May be fixed by #640
Open

Implement add_vertex and remove_vertex for Dynamic Graphs in AdjacencyMatrix #634

asmit27rai opened this issue Mar 12, 2025 · 1 comment · May be fixed by #640

Comments

@asmit27rai
Copy link

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.
@asmit27rai
Copy link
Author

@Kishan-Ved @czgdp1807 I am working on this issue..

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 a pull request may close this issue.

1 participant