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
1 answer

recursive backtracking makeChange

Write a method makeChange that uses recursive backtracking to find all ways to make change for a given amount of money using pennies (1 cent), nickels (5 cents), dimes (10 cents), and quarters (25 cents). For example, when making change for 37…
Amber
  • 21
  • 1
  • 6
0
votes
0 answers

How to establish all the possible tracks

In the given file named "data.in" are written the number of cities N, two cities A and B and the existing roads between them.Ex, the set "2 6" says that between city 2 and city 6 there exist a road.I have to show in a file named"data.out" all the…
0
votes
1 answer

Longest Common Substring using Recursion and DP

I'm trying to find the Longest Common Substring of two strings using Recursion and DP. Please note that I'm not referring to Longest Contiguous subsequence. So, if the two strings were String s1 = "abcdf"; String s2 = "bzcdf" Longest Common…
0
votes
0 answers

Backtracking bruteforce Java password cracker

I have this homework assignment to make a recursive method to crack a password of a given length, n (unlimited and unknown!) made of small English letters, a-z ONLY. Here's the class "Password" that creates a random password: import…
0
votes
3 answers

recursive backtracking - python. not returning value

Problem I am aware that somewhere in my function, I am not returning something I should. I am returning the recursive call, but it appears that I am not returning "all the way out" Context I am doing a depth first search of every single combination…
Anthony Chung
  • 1,467
  • 2
  • 22
  • 44
0
votes
1 answer

Backtracking algorithm to generate all combinations

I have a little problem with this.I want to generate every possible combination.The numbers located in 1D array and it is read from a file. Now I don't know the problem: I know that every combination which will be printed to monitor is in ascending…
Zsombi
  • 84
  • 1
  • 9
0
votes
2 answers

Cryptarithmetic puzzle generic solution in Python 3

I am stuck with this problem statement, My code does work but I used itertools.permutations and that makes it very slow. Moreover, I don't know how to make it generic for all or any input. I think I have to use backtracking but I am not use how to…
0
votes
1 answer

backtracking in javascript, can't update global variable

I'm trying to solve problem of day 9 of the advent of code in javascript. I'm using backtracking for getting all possible routes and then calculate the cost of each one. I'm used to do backtracking in languages like PHP and C++, but never did in JS,…
freinn
  • 1,049
  • 5
  • 14
  • 23
0
votes
1 answer

Python backtracking

I have a basic problem in Python where I have to verify if my backtracking code found some solutions (I have to find all sublists of 1 to n numbers with property |x[i] - x[i-1]| == m). How do I check if there is some solution? I mean the potentially…
FSD
  • 35
  • 3
0
votes
0 answers

Recursive Backtracking Puzzle

Using JAVA, I need to read in a text file containing an n by n table like this (although size may vary): 0110 1000 1001 0010 Assume that n is a number of people. The table describes the relationship between a person(row) and another person(col). …
0
votes
1 answer

In programming terms, what is a backtracking solution?

I have a couple of questions, as to what a backtracking solution really means. Say, you have n options from a current state, does a backtracking solution basically mean that you try out all of those states, and do the same for the…
0
votes
1 answer

Four Color Map Theorem Recursive Backtracking Algorithm

I have coded to following program to implement the Four Color Map Theorem (any map can be colored with only 4 colors without any adjacent regions being the same color, in a nutshell) recursively. Everything compiles, but my output gives me…
0
votes
2 answers

Generating all strings by only two letters having length from 1 to 10?

I want to generate all the strings of length from 1 to 10 by only words '4' and '7' in sorted order example-> 1)4 //first string 2)7 //second string 3)44 //third,because next after 7 should be 44 4)47…
HANOI I
  • 13
  • 3
0
votes
0 answers

Recursive backtracking with cell arrays in Matlab?

I'm working on a function to recursively generate solutions to a given sudoku puzzle represented by a 9x9 array with NaN representing blank spaces utilizing backtracking. function cellSolutions = solveSudoku(PuzzleA) cellSolutions = {}; if…
0
votes
0 answers

Why does my recursive backtracking stop at seemingly random points

I am attempting to generate all closed curves in a finite region of the simple hexagonal lattice. This isn't too important, it is just a finite set of points a distance of 1 away from each other. My code however, will generate closed curves for a…
izaak berg
  • 11
  • 1