Skip to content
← All questions

Why is edge A-B chosen first in the example?

Edge A-B is chosen first because Prim's algorithm is a greedy algorithm that selects the smallest edge connecting the current visited set to an unvisited node. From the starting node A, edge A-B has the minimum weight among all edges incident to A leading to unvisited nodes.

Conditions

  • Node A is the starting visited node.
  • The algorithm follows the greedy rule of picking the minimum-weight crossing edge.

Reasoning, step by step

  1. Identify the current visited set: {A}.
  2. Examine all edges incident to A that lead to unvisited nodes.
  3. Compare the weights of these edges.
  4. Select the edge with the smallest weight, which is A-B.
  5. Add node B to the visited set.

Example

The narrator states, "Prim's is a greedy algorithm, so we're going to choose the smallest edge that connects to an unvisited node, in this case, A to B."

Common misconceptions

  • Choosing the globally smallest edge in the entire graph, regardless of connectivity to the visited set.
  • Selecting an edge that leads to an already visited node.
  • Ignoring edge weights and choosing randomly.

Watch the explanation

Connected concepts

Explore next

Related questions

Meet the concept

↗
Meet the concept

↗
Understand why

↗

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.