How to Build an Algorithm to Solve ANY Sudoku Puzzle

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 พ.ย. 2024

ความคิดเห็น • 15

  • @JikeWimblik
    @JikeWimblik หลายเดือนก่อน

    Theorem: The proposed Sudoku solving algorithm, which utilizes a 45-grid encoding and a 2-SAT solver to iteratively identify and eliminate invalid '1' placements, has a polynomial-time complexity.
    Proof:
    * Sudoku Encoding:
    * The Sudoku puzzle is encoded using 45 grids, where each grid corresponds to a specific number (1-9) and a specific position within a 3x3 subgrid.
    * Each grid contains '1's representing the presence of that number in the corresponding cells and '2's representing its absence.
    * Each grid must have exactly two '1's, ensuring the Sudoku constraints are satisfied.
    * Algorithm Description:
    a) Initialization: All possible '1' placements across all 45 grids are considered.
    b) Iteration:
    i. 2-SAT Solver: For each grid, a 2-SAT instance is constructed based on the current '1' placements and the Sudoku constraints (row, column, and subgrid). The 2-SAT solver is used to identify at least one invalid '1' placement within that grid.
    ii. Elimination: The identified invalid '1' placement is marked, permanently eliminating that possibility.
    iii. Constraint Propagation: The information from the invalid placement is propagated to other grids, potentially identifying more invalid placements.
    c) Termination: The algorithm terminates when a valid solution is found, which occurs when each grid contains exactly two '1's that satisfy all Sudoku constraints.
    * Complexity Analysis:
    * Constant Grid Size: Each grid has a constant size (9 cells).
    * Guaranteed Invalid Placement: In each iteration, at least one invalid '1' placement is guaranteed to be found in one of the grids (as long as the puzzle is solvable).
    * Limited Iterations: The total number of iterations is limited by the total number of possible '1' placements across all grids (45 grids * 9 cells/grid = 405).
    * Polynomial Time per Iteration: Each iteration involves:
    * Constructing a 2-SAT instance, which takes polynomial time.
    * Running the 2-SAT solver, which also takes polynomial time.
    * Marking the invalid placement and propagating constraints, which takes constant time.
    * Overall Complexity:
    * Since the number of iterations is limited by a constant (405), and each iteration takes polynomial time, the overall complexity of the algorithm is polynomial.
    Conclusion:
    The proposed Sudoku solving algorithm, which utilizes a 45-grid encoding and a 2-SAT solver to iteratively identify and eliminate invalid placements, has been proven to have a polynomial-time complexity. This result demonstrates that Sudoku, when encoded and solved using this method, can be solved efficiently.
    Further Considerations:
    * Optimizations: The algorithm can be further optimized by using heuristics to prioritize certain '1' placements or by employing more sophisticated constraint propagation techniques.
    * Generalization: While this proof focuses on Sudoku, the underlying principle of encoding a problem and using a constraint solver to iteratively eliminate invalid possibilities might be applicable to other NP-complete problems. This warrants further investigation and could have implications for the P vs. NP question.

  • @catcanhack
    @catcanhack ปีที่แล้ว +5

    Thanks it really cleared my backtracking concept

    • @JackHeTech
      @JackHeTech  ปีที่แล้ว

      Glad it helped!

    • @catcanhack
      @catcanhack ปีที่แล้ว

      Can u make a video on graph theory like graphs algorithms and stuff ur explanation is very good

    • @JackHeTech
      @JackHeTech  ปีที่แล้ว +1

      @@catcanhack Future upload :)

  • @bojjabheemaraju387
    @bojjabheemaraju387 2 ปีที่แล้ว +1

    Nicely explained!

  • @TechGalDiaries
    @TechGalDiaries 4 ปีที่แล้ว +4

    Hello from another UBC student!

    • @JackHeTech
      @JackHeTech  4 ปีที่แล้ว +1

      hey whats up!?

  • @renji8812
    @renji8812 ปีที่แล้ว

    hi, is this consider a depth first search also?

  • @aminlaribi4200
    @aminlaribi4200 4 ปีที่แล้ว

    Hello , i'm from Tunisia , Good Job man

  • @drjovic
    @drjovic 3 ปีที่แล้ว +1

    good explanation !

  • @christopherteddymienarto9115
    @christopherteddymienarto9115 4 ปีที่แล้ว +2

    Hello from Indonesia, thanks for the explanation

  • @mohammadmudassir4083
    @mohammadmudassir4083 4 ปีที่แล้ว +2

    I am liking your content....... remember my name Mudassir

  • @chrismarklowitz1001
    @chrismarklowitz1001 ปีที่แล้ว

    Oh i see you check every possibilty. I made code that instead of checking every possibilty at every junction it checks for pairs and duos. Like two spaces in a row have 5/9 5/9 that means 5 and 9 cant go anywhere else.