I'm having some trouble thinking about how to locate the central point of a graph; that is, a node on a graph which minimizes the maximal distance to all the other ones.
For example:
Lets say I have a graph with 3 nodes, arranged in a line (like 1-2-3
).
Obviously, it's easy to see that the central point of this graph is 2
. How would I get around to implementing something like that though?
The only algorithms that I know is BFS/DFS/Prim's/ and Kruskal's. Prim's and Kruskal's algorithms don't really apply in this case. I'm thinking that I need to use BFS here? The only issue is, doesn't BFS return a different order depending on which node you start at?
For rather dense graphs:
complexity O(V^3) (with small constants)
If graph is sparse, you can use BFS from each vertice or Johnson's algorithm
(O(V^2+ V*E), O(V^2*logV + V*E))
FYE:
0 1 2 //ecc = 2
1 0 1 //ecc = 1 - central point
2 1 0 //ecc = 2
If you work with tree (as MST has been mentioned in vanished comment) - there is faster method:
O(V + E)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With