Skip to content

773. Sliding Puzzle #875

Answered by mah-shamim
mah-shamim asked this question in Q&A
Nov 25, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We can apply the Breadth-First Search (BFS) algorithm. The idea is to explore all possible configurations of the board starting from the given initial state, one move at a time, until we reach the solved state.

Approach:

  1. Breadth-First Search (BFS):

    • BFS is ideal here because we are looking for the shortest path to the solved state.
    • Each board configuration can be considered a node, and the edges between nodes represent valid moves where the 0 tile is swapped with an adjacent tile.
    • The BFS will explore the board configurations level by level, ensuring that we reach the solved state with the minimum number of moves.
  2. State Representation:

    • We will represent the board as a string (for ea…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Nov 25, 2024
Collaborator

@mah-shamim
Comment options

mah-shamim Nov 25, 2024
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants