Message Boards Message Boards

Algorithm for finding the minimum spanning tree of a graph output the value Null?

Posted 9 months ago

Hello! I'm trying to write an implementation of Prim's algorithm for finding the minimum spanning tree of a graph, using the found implementation of this algorithm in C++ ( https://evileg.com/ru/post/524/ ). When I run my code, I get Null as a result. I tried to display not the spanning tree itself, but, for example, the noedge variable. The answer is displayed as correct, but Null is still assigned next to it. Could you please tell me where the error is in my code and why does Null appear in output regardless of what my function returns?

Attachments:
POSTED BY: Varvara Markova
2 Replies
Posted 9 months ago

Thank you so much!

POSTED BY: Varvara Markova
Posted 9 months ago

Try changing

While[noedge<num-1,
...
]
Graph[vert,EdgeWeight->weights]

to

While[noedge<num-1,
...
];
Graph[vert,EdgeWeight->weights]
POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract