AlgoGenesis / C

AlgoGenesis is a centralized open-source platform dedicated to providing optimized and well-documented algorithm implementations in C. Perfect for both beginners and advanced users, this repository serves as a comprehensive learning resource for solving algorithmic challenges.
MIT License
79 stars 246 forks source link

8-Puzzle Problem #1227

Closed alo7lika closed 1 hour ago

alo7lika commented 2 hours ago

Issue will be closed if:

1) You mention more than one algorithm. You can create a separate issue for each algorithm once the current one is completed.
2) You propose an algorithm that is already present or has been mentioned in a previous issue.
3) You create a new issue without completing your previous issue.

Note: These actions will be taken seriously. Failure to follow the guidelines may result in the immediate closure of your issue.


Name:

[8-Puzzle Problem]

About:

Solve the 8-puzzle problem using backtracking. The puzzle consists of 8 numbered tiles in a 3x3 grid, and the goal is to arrange the tiles in order.

The 8-puzzle problem consists of a 3x3 grid with eight numbered tiles (1-8) and one empty space. The goal is to arrange the tiles in a specific order by sliding them into the empty space. The problem can be solved using various algorithms, with backtracking being one of the efficient approaches.

Approach:

  1. State Representation: Represent the state of the puzzle as a 2D array or a string.
  2. Goal State: Define the goal state (e.g., [1, 2, 3, 4, 5, 6, 7, 8, 0]).
  3. Possible Moves: Identify possible moves for the empty space (up, down, left, right).
  4. Backtracking: Use backtracking to explore all possible configurations of the puzzle:
    • Generate the next possible states by moving the tiles.
    • Check if the new state has already been visited to avoid loops.
    • If the goal state is reached, return the solution path.
  5. Visualization (Optional): Provide a visualization of the steps taken to reach the solution.

Time Complexity:

The time complexity of the backtracking algorithm for solving the 8-puzzle problem is O(b^d), where:

Space Complexity:

The space complexity is O(b*d) due to storing states in memory during backtracking.

Labels:

new algorithm, gssoc-ext, hacktoberfest, level1

Assignees:

Additional Notes:

github-actions[bot] commented 2 hours ago

👋 Thank you for raising an issue! We appreciate your effort in helping us improve. Our team will review it shortly. Stay tuned!

alo7lika commented 2 hours ago

Assign me the task @pankaj-bind