Questions tagged [recursive-backtracking]

Recursive backtracking is a general algorithm for finding solutions to computational problems that incrementally builds partial solutions and drops those which are identified as futile *as early as possible*.

Recursive backtracking is a general algorithm for finding solutions to computational problems that incrementally builds partial solutions and drops as early as possible those partial solutions which are identified as futile i.e. such that can not lead to a correct solution.

It essentially involves building nested loops through recursion. Each loop embodies a series of choices. Each inner loop can accept a partial-solution-so-far and try its own choices in a loop, or reject the partial solution it is presented with, through early exit or an equivalent of the continue or break etc. statement.

The control is inverted in that the full solution is achieved in the innermost loop, which can act on it in a particular manner, like printing it to the output / external file, or calling a callback with the solution as an argument.

The backtracking computational structure is embodied in the states of the nested loops, in each of the nested loops' loop variables.

314 questions
0
votes
0 answers

how to determine the existence of a subgroup that passes given criteria?

As a part of a homework assignment I'm required to write a function, that returns true if a "good" subgroup exists in the array it is given. A "good subgroup" is a subgroup that the sum of a specific field(which is an integer) in each of the group…
TheJedi
  • 1
  • 3
0
votes
1 answer

Sudoku Solver in C++ partially solving

I recently made a sudoku solver in c++. I used a backtracking algorithm to solve it, but there is a problem : for some cases it only solves up to the 5th row. Working case : [6][6] = 2, [4][5] = 1 Case failing after row 5 : [1][1] = 1 I don't know…
0
votes
1 answer

exercise with recursive backtracking

I need help with this exercise: Give the pseudo-code that receives in input an integer n and prints the all possible matrixs nxn where the number of a is greater than or equals to the number of b , for example with n=2: ( the order isn't important…
thinker.92
  • 51
  • 8
0
votes
0 answers

Recursive backtracking to create permutations of given string

I am currently working on a programming assignment where the user inputs a word i.e. "that" and the program should return all valid words that can be made from the given string i.e. [that, hat, at] The issue I am having is that the resulting words…
0
votes
0 answers

How to use this method?

I am very close to finishing my task, but I can't figure out how to call findChange() correctly. My guess is that it needs to be in the main method. But when findChange(); call it, it asks for int, List, List so how do I do this…
Junikin
  • 301
  • 2
  • 14
0
votes
1 answer

why doesn't this backtracking recursion go to other branches?

Given an array, and a goal (number), I have to determine if it is possible to reach goal by adding elements from the array. Here is my code (in javascript), and some results: function check(goal,array) { function add(sum, array) { if (sum ==…
0
votes
1 answer

My c++ program runs, but say "8queens.exe has stopped working"

this code attempts to solve the 4 queens problem, placing 4 queens on a 4*4 chessboard without any of them being able to capture eachother #include using namespace std; int Place(int Chess[][4], int collumn, int i); bool…
user3624385
  • 51
  • 2
  • 2
  • 6
0
votes
1 answer

How to generate all possible numbers using some digits

I am trying to generate all possible numbers starting with a vector of digits that I don't want to occur more than how many times they are in that vector . My first ideea was backtracking but how.... For example: 3 7 5 => 3 5 7 35 37 53 57 73 75 357…
tudoricc
  • 709
  • 1
  • 12
  • 31
0
votes
1 answer

Backtracking and recursion to solve a maze

I am tasked with solving a maze using the method of backtracking and recursion. This is more of a conceptual question about this concept. How is the backtracking call ever reached? From all the examples I have seen it looks as though recursion is…
zach the mack
  • 49
  • 3
  • 11
0
votes
1 answer

I am having trouble with my recursive backtracking algorithm for solving sudoku in C

I can solve an easy puzzle but attempting a slightly harder one is impossible; what am I overlooking? Here is my solver method: int solver (int x, int y) { int a, b, i, j; for (a=1; a<10; a++) { if (checkEverything(x, y,…
-1
votes
1 answer

How to print all the ways to cut off a string - combination

input: "abcd" output: a list of all the ways to cut off the string. [ ["a", "bcd"],["a", "b", "cd"], ["a", "b", "c", "d"], ["ab", "cd"], ["ab", "c", "d"], ["abc", "d"], ["abcd", ""] ] I want a recursive solution. Preferably Java but not need…
-1
votes
1 answer

Explain the use of HashMap: Write a method to compute all permutations of a string whose characters are NOT necessarily unique

I came across the question below, don't fully understand the usage of HashMap, including the lines of map.put(c, count - 1) and map.put(c, count)? Anyone can explain? Permutations with Duplicates: Write a method to compute all permutations of a…
Pingpong
  • 7,681
  • 21
  • 83
  • 209
-1
votes
1 answer

Sudoku Solver Program - no change in output

solveSudoku function is called from main() function. I have written the following function for solving sudoku : bool isFull(vector>& board){ for(int i = 0 ; i < board.size(); i++){ for(int j = 0 ; j <…
Dark Night
  • 33
  • 1
  • 6
-1
votes
2 answers

How do I recursively enumerate all subsets adding to a given sum?

When I try to get the output, it shows same solutions with same element for few times before moving on to another one. I want to get different solutions from the array that is equal to sum For instance, Solution 1 = 14, 8 Solution 2 = 14, 5, 3…
-1
votes
1 answer

Printing the process of a recursive backtracking problem

I have been given this assignment for school: You have been given a puzzle consisting of a row of squares each containing an integer, like this: 6, 4, 1, 3, 3, 1, 4, 1, 1, 0 The bold number on the initial square is a marker that can move to other…
JosephKidd
  • 23
  • 3