Entrance and exit are placed as far apart as possible. Dijkstra's algorithm is used, which is essentially a fancy BFS