You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Graphs/BreadthFirstShortestPath.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
Breadth-first approach can be applied to determine the shortest path between two nodes in a graph. It searches the target node among all neighbors of the starting node. Then the process is repeated on the level of the neighbors of the neighbors and so on.
2
+
Breadth-first approach can be applied to determine the shortest path between two nodes in an unweighted graph. It searches the target node among all neighbors of the starting node. Then the process is repeated on the level of the neighbors of the neighbors and so on.
3
3
(See also: https://en.wikipedia.org/wiki/Breadth-first_search )
4
4
(see also: https://www.koderdojo.com/blog/breadth-first-search-and-shortest-path-in-csharp-and-net-core )
5
5
*/
@@ -23,7 +23,7 @@ function breadthFirstShortestPath (graph, startNode, targetNode) {
23
23
}
24
24
25
25
// visited keeps track of all nodes visited
26
-
constvisited=[]
26
+
constvisited=newSet()
27
27
28
28
// queue contains the paths to be explored in the future
29
29
constinitialPath=[startNode]
@@ -35,9 +35,9 @@ function breadthFirstShortestPath (graph, startNode, targetNode) {
35
35
constnode=path[path.length-1]
36
36
37
37
// explore this node if it hasn't been visited yet
0 commit comments