mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-11-14 06:52:59 +08:00
Merge 42b00c3363
into 2c67b48c21
This commit is contained in:
commit
3c6ed0aa09
@ -8,7 +8,7 @@ export default function bellmanFord(graph, startVertex) {
|
|||||||
const previousVertices = {};
|
const previousVertices = {};
|
||||||
|
|
||||||
// Init all distances with infinity assuming that currently we can't reach
|
// Init all distances with infinity assuming that currently we can't reach
|
||||||
// any of the vertices except start one.
|
// any of the vertices except start one and try to get to that point.
|
||||||
distances[startVertex.getKey()] = 0;
|
distances[startVertex.getKey()] = 0;
|
||||||
graph.getAllVertices().forEach((vertex) => {
|
graph.getAllVertices().forEach((vertex) => {
|
||||||
previousVertices[vertex.getKey()] = null;
|
previousVertices[vertex.getKey()] = null;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Prim's Algorithm
|
# Prim's Algorithm
|
||||||
|
|
||||||
In computer science, **Prim's algorithm** is a greedy algorithm that
|
In computer science, **Prim's algorithm** is a greedy algorithm that
|
||||||
finds a minimum spanning tree for a weighted undirected graph.
|
finds a minimum spanning tree(shortest distance to reach every node) for a weighted undirected graph.
|
||||||
|
|
||||||
The algorithm operates by building this tree one vertex at a
|
The algorithm operates by building this tree one vertex at a
|
||||||
time, from an arbitrary starting vertex, at each step adding
|
time, from an arbitrary starting vertex, at each step adding
|
||||||
|
Loading…
Reference in New Issue
Block a user