January 2018
Intermediate to advanced
332 pages
7h 36m
English
The pseudo code for BFS is very similar to DFS, the main difference is that in BFS we iterate over all the connected nodes first before moving out to another level looking for our target node:
INITIALIZE paths, nodes to visit (queue), visited nodesSET start node as visitedWHILE nodes to visit exist GET the next node to visit as current node from top of queue IF current node is target INITIALIZE result with target node WHILE path retrieval not at source EXTRACT how we got to this node PUSH to result FORMAT and return relationship ELSE LOOP over the entire graph IF node is connected to current node SET its path as current node MARK node as visited PUSH it to queue for visiting breadth wiseRETURN Null that is no result
Sounds very ...
Read now
Unlock full access