Skip to content
← All questions

How do you start Prim's algorithm on a graph?

To start Prim's algorithm, create an empty list called 'visited' to track touched nodes, then pick an arbitrary starting node and add it to the visited list.

Conditions

  • The graph is weighted and connected.
  • You have a mechanism to track visited vertices (e.g., a list or set).

Reasoning, step by step

  1. Initialize an empty 'visited' list.
  2. Select any arbitrary node as the starting point.
  3. Add the starting node to the 'visited' list.

Example

The narrator says, "To start, create an empty list called visited... The next step is to pick an arbitrary node... Let's start with A in our graph. First, add A to the visited list."

Common misconceptions

  • Forgetting to initialize the visited list.
  • Thinking the starting node must be the one with the smallest degree or specific label.
  • Not adding the starting node to the visited list immediately.

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.