We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Algorithm: Pick a starting node, at each step pick the cheapest edge (smallest weight) and add the node to the current tree. Repeat for n-1 steps.
Initialize distances to infinity for x in 1 to N: dist[x] = INF
Set distance to root node to 0 dist[start] = 0 // start can be any node
Pick the minimum edge loop through all x from 1 to N and find minimum dist that's not visited
Mark visited visited[node] = true
Update neighbors loop through neighbors of the node: dist[j] = min(dist[j], mat[x][j])
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Prim's Algorithm (Finding the Minimum Spanning Tree) O(N^2)
Algorithm: Pick a starting node, at each step pick the cheapest edge (smallest weight) and add the node to the current tree. Repeat for n-1 steps.
Initialize distances to infinity
for x in 1 to N: dist[x] = INF
Set distance to root node to 0
dist[start] = 0 // start can be any node
Pick the minimum edge
loop through all x from 1 to N and find minimum dist that's not visited
Mark visited
visited[node] = true
Update neighbors
loop through neighbors of the node: dist[j] = min(dist[j], mat[x][j])
The text was updated successfully, but these errors were encountered: