Algorithms – Solving Breadth-First Graph Search Problems

algorithmsgraphgraph-traversal

I thought I was doing breadth-first graph search correctly, but my instructor's grading script is telling me that my answer is incorrect.

From the instructions:

Consider a breadth-first graph search on the graph below, where S is the start and G is the goal state. Assume that ties are broken alphabetically (so a partial plan S->X->A would be expanded before S->X->B and S->A->Z would be expanded before S->B->A). You may find it helpful to execute the search on scratch paper.

Please enter the final path returned by breadth-first graph search in the box below. Your answer should be a string with S as your first character and G as your last character. Don't include arrows or spaces in your submission. For example, if you believe the path is S->X->G, please enter SXG in the box.

breadth-first search on graph

I got and input the answer SACBG, which the grading script marked as incorrect. ("Your input was evaluated as SACBG, which is not correct.")

Here are my steps for the breadth-first graph search on the above graph using the algorithm at http://en.wikipedia.org/wiki/Breadth-first_search#Pseudocode:

  1. Enqueue the root node S. Queue = [S], Path = []
  2. Dequeue S and examine it. Queue = [], Path = [S]
  3. Enqueue S's children, A and C. Queue = [A, C], Path = [S]
  4. Dequeue A and examine it. Queue = [C], Path = [S, A]
  5. A has no children. Dequeue C and examine it. Queue = [], Path = [S, A, C]
  6. Enqueue C's children B and G. Queue = [B, G], Path = [S, A, C]
  7. Dequeue B and examine it. Queue = [G], Path = [S, A, C, B]
  8. B's only child G is already in the queue. Queue = [G], Path = [S, A, C, B]
  9. Dequeue the goal node G and examine it. Quit the search and return. Queue = [], Path = [S, A, C, B, G]

A node is placed in the path when it is dequeued and examined.

Ties are broken alphabetically as required in the instructions.

What am I doing wrong?

Best Answer

The problem appears to be that your answer is the order in which the nodes are evaluated by the breadth first search but what the questions asks for is the final path from S to G that the search would find.

I think the answer the question is looking for is SCG.

Easiest way to confirm would be to talk to your instructor.

(A depth first search using the same alphabetical precedence rules would return SCBG as the path.)

Related Topic