I have a Graph that I'm making using an adjacency matrix to hold edge values. The noEdge value is zero and all edgeweights are positive integers. I have to delete a node from this graph and I'm having trouble figuring out how to update the Adjacency matrix after the deletion of the label from my labels vector. I know I have to shift the values but I can't quite figure out in code/algorithm format.

Any idea on a good way to implement this in code/an algorithm?


5 Years
Discussion Span
Last Post by firstPerson

When you delete a node from a graph, to update your adjacency matrix you can either remove the column and row associated for that row. For example

Let node = 1 2 3
And its initial adjacency matrix be:

  1 2 3
1 0 0 0
2 0 0 0
3 0 0 0

if you delete node 2, your adjacency matrix should remove all reference for node 2. Hence afterwards it should look like

1  3
1 0  0
3 0  0

Or you can take another approach, a flag approach, for example have -1 to mean deleted

1  2 3
1  0 -1 0
2 -1 -1 -1
3  0 -1 0

Edited by firstPerson: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.