-
Notifications
You must be signed in to change notification settings - Fork 314
Open
Description
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:
add_vertex: This method should add a new vertex to the graph and update the adjacency matrix and edge weights accordingly.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
-
add_vertex:- Add the new vertex to the
verticeslist. - Update the
matrixdictionary 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.
- Add the new vertex to the
-
remove_vertex:- Remove the vertex from the
verticeslist. - Remove the vertex from the
matrixdictionary and all its associated edges. - Remove any edge weights involving the vertex from the
edge_weightsdictionary.
- Remove the vertex from the
Metadata
Metadata
Assignees
Labels
No labels