Breadth First Search/Traversal
807603Nov 28 2007 — edited Dec 4 2007Today we went over Breadth First Searches/Traversals and I think I understand it. Basically it works by picking a starting node and adding it to a queue. Then you remove it (and add it to a visited list) and add back to the queue anything that it links to (also perhaps with a count to keep track of the path length). Then you remove the next thing from the queue and add back anything that it links to (provided its not already visited). Then when the Queue is empty you look at the visited list and you can go through it and see all of the shortest paths to every node.
I'm trying to apply a breadth first search to a problem I'm working on but can't seem to figure out a way to do it that makes sense. For those of you that are engineers I basically have a simple Mealy state machine. In other words, I have a graph and I go from one node to another depending on what the input is.
The problem is, we don't know what state we're in and we have to find the length of the shortest common path from any state to get to a common state, ie the input sequence "a" followed by "b" will always result in us being in state "X" no matter what state we started in and has length 2.
Any ideas as to how to apply a BFS to this?
Thanks