it is broken up into several parts. This algorithm works on weighted graphs