Nusha
Nusha

Reputation: 262

Lightest paths tree

I need to write algorithms finding the lightest path tree in directed and weighted graph. (should be efficient as possible) I'm getting a vertex S and need to build a paths tree from S to all vertex that can be approach from S so the paths in the tree are the lightest ( path weight is the path without the ends)

I thought about first calculating all the distances from S And then for each path there will be a new weight: The weight minus The ends And then on the graph with the new weights to run dijkstra...

Will it work? Is it efficient enough? How to calculate the distances?

Upvotes: 1

Views: 489

Answers (2)

amit
amit

Reputation: 178441

Your comments suggest you are actually looking for the shortest path from a single source - to all vertices.

Have a look at how Dijkstra's algorithm works. The algorithm starts with a tree of size 1 (the source alone), and iteratively adds vertices to the tree. In the end, the tree created by dijkstra's algorithm, represent the shortest path from the source to each of the nodes in the graph.

Note that dijkstra's algorithm, needs a weight function on edges, while your weight function is on vertices. It can be solved easily by defining a new weight function w':E->R: w'(u,v) = w(u) (it works since you don't want to count the end).

Upvotes: 3

jrennie
jrennie

Reputation: 1957

It sounds like you're asking for a minimum spanning tree. The wikipedia page discusses algorithms.

Upvotes: 0

Related Questions