Breadth First Search solution on paper

BFS_answer1

I started out by copying the grid onto paper, then drawing a quick reference to the search order.

Then, stepwise:

(q) = queued

  • = explored
  1. I Queued A, which returned B and G
    (q)A *B *G

  2. I Queued B (following the FIFO or first in, first out principle), returning C
    A (q)B G *C

  3. Queued G, which returned H
    A B (q)G C *H

  4. Queued C, which returned E then D
    A B G (q)C H *E *D

  5. Queued H, which returned L
    A B G C (q)H E D *L

  6. Queued E, which returned F
    A B G C H (q)E D L *F

  7. Queued D which returned M
    A B G C H E (q)D L F *M

  8. Queued L, returning nothing
    A B G C H E D (q)L F M

  9. Queued F, returning I
    A B G C H E D L (q)F M *I

  10. Queued M, returning K
    A B G C H E D L F (q)M I *K

  11. Queued I, returning Z
    A B G C H E D L F M (q)I K *Z

Then I got the shortest path by following the directions and moving stepwise (i.e. in the given order) through the queue path.

Hope this is helpful to someone! Really excited to implement this.

2 Likes

Wow! Impressive work :clap:

1 Like

Thanks!

Privacy & Terms