Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert adjacency matrix to a distance or hop matrix

Is it possible to convert an adjacency matrix of ones and zeros as defined here into a distance matrix as defined here where each link would be of unit length 1?

like image 848
pyCthon Avatar asked Oct 09 '22 04:10

pyCthon


1 Answers

An adjacency matrix of ones and zeros is simply a representation of an undirected graph. To get the distances between any two vertices of an unweighted graph, you can use breadth first search.

Assuming you have an n by n matrix:

for each vertex i:
    initialize an nxn matrix M
    run breadth-first search starting at i
    copy distances into row i of M
    return M
like image 164
tskuzzy Avatar answered Oct 12 '22 23:10

tskuzzy