Breadth first search with bidirectional edges

367 Views Asked by At

Since this is a Breadth first search I would say that the answer would be S-B-E-F-G since it is the first path to get searched and the goal is in that path. Would that be correct? I am a little confused since bidirectional edges also are used in this.

Consider the search space with this graph, where S is the start state and G is the goal. All edges are bidirectional.

enter image description here

What is the path according to Breadth-first search as a sequence of nodes starting at S and ending at G? Assume the successor functions work so that nodes are explored in alphabetical order whenever possible.

Possible answers:

  1. S-B-E-G
  2. S-B-E-F-G
  3. S-C-G
1

There are 1 best solutions below

1
On BEST ANSWER

Breadth first will

  1. Start with $S$. It finds $S \ne G$, so:
  2. It checks the children of $S: B, C, D$ in that order. It finds none of them are $G$, so it expands each of them:
  3. The children of $B$ are $E$ and $S$. $E\ne G$, and $S$ has already been checked, so it is skipped.
  4. The children of $C$ are $G$ and $S$. Success!

So the path it will find is $S - C - G$

It is tempting to think that when it checks $E$ it will go on down to $E$'s children, but that is depth first, not breadth first.