Questions tagged [backtracking]
Backtracking is a general algorithm for finding solutions to some computational problem, that incrementally builds candidates to the solutions, and rejects continued processing of tracks that would lead to impossible solutions.
84
questions
3
votes
1
answer
153
views
Pentomino solver in Python
When I was a child, I used to play Ubongo board game, recently I discovered Pentomino puzzle and I wanted to create a custom solver in python for it. Here is what I got:
...
1
vote
1
answer
97
views
Positioning boxes in a box with backtracking in Java
A large cube-shaped box has the dimensions 5x5x5. This box is to be completely filled with smaller boxes. Possible candidates are:
...
1
vote
0
answers
183
views
Backtracking graph algorithms for a word puzzle in Python
Motivation
Recently, Buzzfeed released a browser-based puzzle game called "Pyramid Scheme." It is available at the following link. The puzzle in an initial state looks like this:
To solve ...
1
vote
2
answers
345
views
Count the number of ways N queens can be placed on an N✕N chess board
The n-queens puzzle is the problem of placing n queens on an n✕n chessboard such that no two queens attack each other.
Given an integer n, this code returns the number of distinct solutions to the n-...
1
vote
1
answer
105
views
2 slow and barely working sudoku solving implementations
The code below is working however, if more zeros (empty cells) are added to the sudoku grid g, it takes longer to run, if it ever finishes.
...
2
votes
0
answers
134
views
Followup: Use backtracking to put as many ships on a battleship-board as possible
I created a simple battleship game and wanted to be able to place as many ships on my board as possible.
The logic to place the ships uses some kind of backtracking to find a correct placement.
...
3
votes
1
answer
130
views
Exceeded time limit on Trie search with Backtracking using Swift
I have been trying to solve Trie related problems over at leet code and came across this interesting problem 211. Design Add and Search Words Data Structure
Here is the question for convenience:
211. ...
5
votes
2
answers
572
views
Leet Code 139 (Word Break) using a trie with recursion
I was attempting to solve LeetCode 139 - Word Break
Given a string s and a dictionary of strings wordDict, return
...
9
votes
2
answers
1k
views
Sudoku Solver in C without recursion
I am trying to learn backtracing , so i wrote program for Sudoku
It solves sudoku in approx. 1 ms in online c compiler
but this one sudoku puzzle is taking approx. 35 sec in that online c compiler ...
0
votes
1
answer
145
views
Speed up performance of backtracking solution for Sudoku solver
I can't improve the performance of the following Sudoku Solver backtracking solution. I know there are 3 loops here and they probably cause slow performance but I can't find a better/more efficient ...
3
votes
1
answer
580
views
Optimize "Fill magic square" in python with backtracking
I have written a python program with backtracking that fills a n * n magic square. It solves for n = 4 in 4.5 seconds but gets stuck when I run it for n = 5 on my ...
1
vote
0
answers
85
views
How can I optimise my recursive backtracking sudoku algorithm?
I've tried optimising my program by removing invalid values for possible spaces instead of searching from 1-9, and by choosing values with the lowest number of empty spaces in its row and column, but ...
6
votes
1
answer
170
views
Rust based Sudoku solver using backtracking
I've just started learning rust and have written a basic sudoku solver, however it seems to run much slower than I expected. So I'm looking for any possible performance improvements as well as any ...
6
votes
2
answers
497
views
Python backtracking algorithm to solve sudoku
I have recently gotten back into writing python and i decided to take up a project of writing a backtracking algorithm in python to solve Sudoku puzzles
How it Works
A matrix is declared to represent ...
5
votes
1
answer
2k
views
Farmer, Wolf, Goat and Cabbage Problem: full decision tree in C
I put a backtracking algorithm around the Farmer, Wolf, Goat and Cabbage problem - to see if there are any interesting branches, besides the (two) 7-step solutions.
WGC Problem: A Farmer with a wolf, ...