graph - Getting stuck and running out of nodes in Prim's algorithm? -


so have graph

enter image description here

and i'm trying build minimum spanning tree. starting @ vertex go a-b-f-e-d , after there's no place go, considering adjacent vertexes d part of tree, how keep going?

also how calculate range of values of new edge part of minimum spanning tree?

thanks in advance guys.

i think have slight misunderstanding of how prim's algorithm works. based on description gave above, looks think prim's algorithm works this:

  • start @ node.
  • look @ nodes connected current node haven't visited.
  • go cheapest of these nodes.
  • repeat until nodes covered.

this close how prim's algorithm works, it's not right. in prim's algorithm, there's no notion of "current" node. instead, have 2 sets of nodes: nodes you've added in, , nodes haven't. prim's algorithm works this:

  • start @ node. add "in" set.
  • look @ nodes connected "in" set haven't been added "in" set.
  • add cheapest of these nodes "in" set.
  • repeat until nodes in "in" set.

in graph gave above, started @ node a. following algorithm, @ nodes connected , take cheapest (b) , add "in" set. "in" set contains , b.

now, @ nodes connected anything in "in" set. nodes d, f, e, , h. of those, cheapest h, add h our "in" set, a, b, , h.

we again @ nodes connected anything in "in" set. nodes d, f, e, i, , g. cheapest of these f, add in.

if repeat process until nodes added, , keep track of edges added in course of doing so, you'll end minimum spanning tree overall graph.

hope helps!


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -