Reputation: 922
If the graph was unweighted you would just go to the row/column (in degree/out degree) of that vertex and count the 1s. But what about a weighted graph? My professor said just count all the non-zero edges but to my understanding it is possible for an edge to have a weight of zero, correct?
So in short: Given an adjacency matrix of a weighted graph with weights of zero allowed, how can you count the degree of a certain vertex?
Upvotes: 0
Views: 1546
Reputation: 641
It doesn't really make sense to have a zero-weight edge in a weighted graph. That depends on what your weights mean for the system you are modelling, of course.
You could have a graph where some have weights and some do not, potentially. In which case, you can't record this as an adjacency matrix since you can't distinguish between 'no edge' and 'unweighted edge'.
If you really needed to have a graph where some edges have no weight encoded in a matrix, then I guess you could do some kind of simple trick like add 1 to all weights when storing in the matrix, then subtract one when you want to calculate properties over those weights.
Upvotes: 0