ps2n1 - 1. Algorithm: 01. function transform(G, M, e) 02....

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1. Algorithm : 01. function transform(G, M, e) 02. if e is in M already then 03. if e.cost < old cost then 04. // return the same minimum spanning tree 05. return M 06. else 07. remove e from M 08. let n = e.cost 09. let e' = e 10. // calculate the two strongly connected components 11. do a DFS starting with the first vertex of e and mark every node in first-component set 12. do a second DFS starting with the second vertex of e and mark each node in the second-component set 13. foreach edge e2 in G's edge list do 14. if the first vertex in e2 is in first-component and second in second-component 15. or vice versa then 16. if e2.cost < n then 17. e' = e2 18. n = e2.cost 19. end 20. end 21. end 22. add e' into M and return M 23. end 24. else 25. if e.cost < old cost then 26. add e into M 27. do a DFS on M starting with one of the nodes in e and terminate when we reach the other node of e. Mark each edge it encounters in the set cycle-edges, including e 28. find the maximum edge in cycle-edges and remove it from M 29. return M 30. else 31. return M 32. end 33. end 34. end Description : Given inputs G the graph, M the minimum spanning tree, and e the edge we altered, then we look at four different cases: If e was originally in M and e’s new cost < old cost, then nothing was altered and we just
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

ps2n1 - 1. Algorithm: 01. function transform(G, M, e) 02....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online