Skip to content

Commit 95e4a6e

Browse files
committed
conclusion section
1 parent e525640 commit 95e4a6e

File tree

1 file changed

+10
-4
lines changed
  • src/content/post/2025/07-31-maze-solver

1 file changed

+10
-4
lines changed

src/content/post/2025/07-31-maze-solver/index.mdx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const { coord, path } = stack.pop()!;
191191

192192
This is the array of coordinates that represents possible directions for a movement. This array is iterated over in the algorithms inner loop.
193193

194-
```ts
194+
```ts title="src/utils/constants.ts"
195195
export const directions: Direction[] = [
196196
{ x: 0, y: 1 }, // up
197197
{ x: 1, y: 0 }, // right
@@ -200,7 +200,7 @@ export const directions: Direction[] = [
200200
];
201201
```
202202

203-
Here is the complete BFS implementation so we can have a better idea what we are working with:
203+
Here is the complete BFS implementation (since all of the 4 algorithms share the most of the same base) so we can have a better idea what we are working with:
204204

205205
```ts title="src/solvers/maze-solver-bfs.ts"
206206
export class MazeSolverBFS extends MazeSolver {
@@ -277,7 +277,7 @@ Not all graphs have edges with uniform weights. In such cases we must use algori
277277

278278
Dijkstra is aware of the cost between two nodes (edge weight) and it will take it into account when selecting the next node. It uses a priority queue to keep the cost history.
279279

280-
```ts
280+
```ts title="src/solvers/maze-solver-dijkstra.ts"
281281
// Take the first element from the priority queue.
282282
// Choose the node that ads minimal cost.
283283
queue.sort((a, b) => a.cost - b.cost);
@@ -297,7 +297,7 @@ Dijkstra keeps a history of the cost of the current path and when selecting the
297297

298298
A\* is same as Dijkstra but beside the keeping the history it uses the heuristics function to predict the future - the direction in which the end node could be.
299299

300-
```ts
300+
```ts title="src/solvers/maze-solver-a-star.ts"
301301
protected heuristic(a: Coordinate, b: Coordinate): number {
302302
// Manhattan distance as the heuristic.
303303
// Can only move horizontally or vertically, not diagonally. In "rectangles".
@@ -324,6 +324,12 @@ If the heuristic function is well chosen it will make A\* more efficient than th
324324

325325
## Conclusion
326326

327+
On this example we could see how algorithm analysis and design is a very sensitive and subtle discipline, that leaves no room for a low focus or lack of understanding of the domain. Although BFS, DFS, Dijkstra, and A* share a majority of the implementation, just a subtle change in the code can cause a dramatic change in the behavior.
328+
329+
In the demo app you can tweak the predefined mazes in the `tests/fixtures/*.txt` files and try to make your own observations. You can also check the resources and the interactive playground listed in the [References](#references) section.
330+
331+
Did you experiment with maze solving and pathfinding algorithms yourself before? Let me now in the comments.
332+
327333
## References
328334

329335
- Some visualized algorithms behavior https://www.youtube.com/watch?v=GC-nBgi9r0U

0 commit comments

Comments
 (0)