Search algorithm used to traverse or serach through a graph. Start from a grpah vertex, and traverse all this vertext's neighboor nodes first, then move to next level.
- For graph, we need to maintain a
visited array
to record which node is visited. - For BFS, we use queue. The FIFO data structure promise to traverse all nodes in the higher level before go to next level.
- source code (I used my own queue, but in face we can just use JavaScript's array to simulate a queue, use
shift
to dequeue,push
to enqueue).