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?

Thanks

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.