How we find MST (Minimum Spanning Tree)
after add new node or change distance of ways?
I need help to solve this. Can anybody help me?
Thanks.
When adding new edges:
You will need to perform a graph traversal, the easiest is DFS for this, from one of the sides of the modified/new edge. If you can back to a node you were to before, you have a cycle.
In that cycle, you will need to remove the largest edge. You will get a tree again, and it is the minimal spanning one.
If you are changing edge weights, you will need to:
Again, you get a new minimal spanning tree.
Overall, this is O(V+E)
, times a small factor of inverse Ackermann.