I have a matrix 5×5 (25 nodes). Is there a formula that I can find the shortest distance between 2 node i and j in the matrix ?
Note: distance between 1 node and its neighbor is 1 unit.
=================
In my observation, there are many paths with the same distance between those 2 nodes i and j
so i’m not sure if there is a formula to calculate the shortest one? I appreciate if anybody can help. Thanks.
Ex:
* * * i *
* * * * *
* * * * *
* * * * *
* j * * *
Shortest distance between i and j is 6 units.
I believe what you need is the
L1distance, also called the Manhattan distance. So if your two nodes have matrix indices(i1,j1)and(i2,j2), then the shortest distance between them is|i1-i2|+|j1-j2|.This is of course, assuming you can’t move diagonally.