Update breadth-first-search.english.md (#18900)
This commit is contained in:
committed by
Jonathan Grah
parent
ec7c3ced0e
commit
e6402d3d6f
@ -8,7 +8,7 @@ challengeType: 1
|
||||
<section id='description'>
|
||||
So far, we've learned different ways of creating representations of graphs. What now? One natural question to have is what are the distances between any two nodes in the graph? Enter <dfn>graph traversal algorithms</dfn>.
|
||||
<dfn>Traversal algorithms</dfn> are algorithms to traverse or visit nodes in a graph. One type of traversal algorithm is the breadth-first search algorithm.
|
||||
This algorithm starts at one node, first visits all its neighbors that are one edge away, then goes on to visiting each of their neighbors.
|
||||
This algorithm starts at one node, first visits all its neighbors that are one edge away, then goes on to visiting each of their neighbors and so on until all nodes have been reached.
|
||||
Visually, this is what the algorithm is doing.
|
||||
<img class='img-responsive' src='https://camo.githubusercontent.com/2f57e6239884a1a03402912f13c49555dec76d06/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f636f6d6d6f6e732f342f34362f416e696d617465645f4246532e676966'>
|
||||
To implement this algorithm, you'll need to input a graph structure and a node you want to start at.
|
||||
@ -112,7 +112,8 @@ queue.push(neighborIdx[j]); // Add new neighbors to queue
|
||||
}
|
||||
}
|
||||
}
|
||||
return nodesLen;}
|
||||
return nodesLen;
|
||||
}
|
||||
```
|
||||
|
||||
</section>
|
||||
|
Reference in New Issue
Block a user