Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hlsxx/8-puzzle-cpp

Solving 8-puzzle with BFS and DFS algorithms
https://github.com/hlsxx/8-puzzle-cpp

8-puzzle 8-puzzle-cpp 8-puzzle-problem 8-puzzle-solver bfs bfs-cpp dfs dfs-cpp

Last synced: 5 days ago
JSON representation

Solving 8-puzzle with BFS and DFS algorithms

Awesome Lists containing this project

README

        

# 8-puzzle with C++

The 8-puzzle is a classic sliding puzzle that consists of a 3x3 grid with eight numbered tiles and one empty space. The goal of the puzzle is to rearrange the tiles by sliding them into the empty space, aiming to achieve a specific configuration, typically with the numbers arranged in ascending order.

![BFS](./images/8-puzzle.gif?raw=true "8-puzzle")

## Solve with BFS and DFS algorithms

Breadth-First Search (BFS) and Depth-First Search (DFS) are two fundamental algorithms used for traversing or searching graph and tree data structures.

## Example
Input matrix:
1 2 3
0 4 6
7 5 8

### Breadth-First Search (BFS)
Depth: 3
Nodes count: 8

![BFS](./images/bfs.jpg?raw=true "BFS")

### Depth-First Search (DFS)
Depth: 11
Nodes count: 12

![DFS](./images/dfs.jpg?raw=true "DFS")