0

Hi all I am searching an algorithm to determine which are the 2 furthest node in an undirected unweighted graph. So I mean only in terms of edges. For example in the photo should be the two marked in red with a distance of 4 edges.

enter image description here

Ciao Ciao
  • 19
  • 5
  • 1
    Does this answer your question? [finding longest path in a graph](https://stackoverflow.com/questions/29320556/finding-longest-path-in-a-graph) – trincot Jun 09 '21 at 07:08

1 Answers1

0

A more complete result can be given thanks to the Dijkstra algorithm, which will give you the distance between each points of the graph. In this simple implementation, the graph is represented as a matrix of neighborhood, and you get all the distances. You can adapt the code to not print the result in the shell but to return a matrix of distances or a dictionnary, and take the max.

Robin maltaros
  • 211
  • 3
  • 5