Challenge: Prim's Algorithm | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/977854-data-structures-algorithms-in-swift/lessons/28

@catie, @jessycatterwaul, could you please explain a bit more detailed why is X <= 5. I thought it should have weight <= from 1 to 4 && <= from 3 to 4 && <= from 3 to 4 && <= from 3 to 6 to 4. Therefore X should <= 5 && 4 + X <= 5 so X <= 1.
Please explain where is my mistake. :confused:

Hi! I don’t understand how to interpret the symbology in your post. Can you please rephrase?

You are right - it does not look very clear unfortunately.
I thought X should satisfy all the conditions below:

  1. Weight from vertex 1 to vertex 4. X<=5
    AND
  2. Weight from 3 to 4. X<=5
    AND
  3. Total weight 3 to 6 to 4 . X + 4 <=5

Why we do not need to apply 3rd condition?

@jessycatterwaul @catie Can you please help with this when you get a chance? Thank you - much appreciated! :]

Sorry, I don’t know why I wasn’t notified about your response!

It seems that you’re not taking into consideration that node 6 is in the graph. We’re not trying to find the fastest route to node 4; we’re assessing a complete minimum spanning tree.

1 Like