Questions tagged [backtracking]

Backtracking is a general algorithm for finding solutions to some computational problem, that incrementally builds candidates to the solutions.

Backtracking is an important tool for solving constraint satisfaction problems, such as crosswords, verbal arithmetic, Sudoku, and many other puzzles. It is often the most convenient (if not the most efficient) technique for parsing, for the knapsack problem and other combinatorial optimization problems. It is also the basis of the so-called logic programming languages such as Icon, Planner and Prolog. Backtracking is also utilized in the (diff) difference engine for the MediaWiki software.

1349 questions
-4
votes
1 answer

Getting a list of numbers from 0 to n, which has no adjacent consecutive numbers and the value of the number is not equal to its index

So, I want a function to return a list (l), which has values (0, 1, 2, 3, ... , n) but consecutive numbers cannot be adjacent to each other. And the value of the number cannot be equal to its index. For eg. for n = 4, def main(n) ---code goes…
hvrc
  • 19
  • 3
-4
votes
1 answer

Python: function returns a list even though it shouldn't

I made a program that solves 4x4 sudoku using backtracking algorithm (the grid is split into 2 parts which are also split into 2 parts with 4 cells) , it has 3 functions, first prints the grid, second checks if a number can be placed into a cell,…
Lunix
  • 1
  • 1
-4
votes
1 answer

Math riddle from Math Olympiad

Determine all triples (a, b, c) of positive integers such that each of the numbers: ab-c, bc-a, ca-b is a power of two. How to solve this with backtracking? Tried but have not succeed..
-5
votes
2 answers

c++ sudoku program using Back tracking, Segmentation fault (core dumped) ,all suggestions are welcomed

#include using namespace std; //defining 9X9 grid. int a[9][9] ={{0,0,3,0,9,2,6,0,0}, {1,0,0,3,0,0,8,0,0}, {0,0,5,0,1,0,0,4,0}, {0,3,0,0,0,0,2,5,8}, …
-5
votes
1 answer

Letter combinations of a phone number

Given an digit string,we need to print all letter combinations the number represents For input "23",output should be ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"]. class Solution { public: char…
user3615045
  • 173
  • 2
  • 8
-5
votes
1 answer

Python Backtracking (queens checkboard)

Ok so finally after hours and hours of struggling with my head I finally understood how backtracking works. Though I still think there are secrets left to be understood. Anyways, I'm trying to create the 4-queens problem on the checkboard.…
-5
votes
1 answer

Eight Queens using backtracking and recursion c++

I have just learned backtracking and recursion, and have an assignment for using it in the Eight Queens Problem. I am supposed to prompt the user to enter a row, and then procedure place_next_queen(bool& done) should attempt to place the next queen…
djokluv
  • 1
  • 3
-5
votes
2 answers

using backtracking recursion c++

I need help with writing a backtracking recursion code in c++ that reach the min steps from 1 number to other number. you can only use +1 or *2 for example getting 23 from 10 by shortest is: ((10+1)*2)+1 has 3 steps, or getting 65 from 12:…
Talor T
  • 69
  • 1
  • 8
-5
votes
1 answer

Chasing game in C

I'm stuck with a quite complex problem: On an MxN field containing a chicken, an eagle and a yard, the chicken tries to escape the eagle (by entering the yard), and the eagle tries to catch the chicken. The chicken escapes when reaches…
Camelia
  • 5
  • 3
1 2 3
89
90