6 × 6 board · knight from (0,0) to (4,4)
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
·
queue · cells to expand
front →
(empty)
← backBFS over knight moves
▸1queue = [start]; dist(start) = 02while queue not empty:3 cell = queue.dequeue()4 if cell == target: return dist(cell)5 for each of the 8 knight moves:6 if neighbour in bounds and unvisited:7 dist = dist(cell) + 1; enqueue it8return -1 // unreachable
state
- start(0,0)
- target(4,4)