## Question:

So my professor in college gave us a quiz, using Breadth-First Search , I answered this question as follows:-**S -> {A,B} -> {C,D,E} -> {G2}**

since we found the goal then we stop , so the answer is d(otherwise) however the professor gave us the answer as b.

Can anyone explain why and how to solve this type of questions ?

## Answer:

Ah, I just saw that you ended at G2 as opposed to G1. (At first I thought the problem was you wanting to return an answer as a list of lists.)I would agree with you that the answer is (D). G2 is discovered as a neighbor of D, before G1 is discovered as a neighbor of E.

I don’t see how one would arrive at G1 first, unless doing something weird like sorting on insertion into the queue.

If you have better answer, please add a comment about this, thank you!