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

Unable to get an output for sudoku solver using backtracking

I started working on a sudoku solver using backtracking and recursion. I am unable to print the solved Sudoku. I have tested the possible(y,x,n) method and it works. The program finishes with Process finished with exit code 0 but without printing…
0
votes
2 answers

In factorial using recursion when n becomes zero (n= 0) why is it not returning final result 1?

def factorial(n): if n == 0 : return 1 return n* factorial(n-1) Here when n reaches 0 the result is 24. Why is the result not 1?
0
votes
1 answer

Comprehending the walk through of a recursive code

If I keep my hand on each line of code as we go through, then when we hit a function call, my hand goes to the function which is called and that function begins to execute, after that my hand returns back to the line where the function was called.…
0
votes
0 answers

segment fault in recursion, when trying to backtrack during sudoku solver algorithm in c++

I did the same question a while ago, but It got closed. I'll try to express myself better this time. I want to make an algorithm that can solve a sudoku puzzle, looks like It is working, but in the backtracking part(where I need to go back to a…
0
votes
2 answers

Sudoku Backtracking Algorithm Solver raising a RecursionError

I'm creating a text based Sudoku solver and everytime I run the code I hit a RecursionError error. I thought something was wrong with my code so I increased the recursion depth and it works fine, I'm just not sure how to rewrite my function so that…
Mercrist
  • 99
  • 1
  • 9
0
votes
0 answers

Why is my Sudoku Solver not changing passed array values in TypeScript?

Ok, so I looked into the stack overflow site and found some similar questions, but none of them seem to give me the solution to my problem here. If I am correct, arrays and objects are passed by reference automatically in JavaScript and TypeScript,…
0
votes
0 answers

Find shortest path for rat in the maze allowed to break a wall using backtracking and recursion. What is wrong in my code?

This is a code for finding shortest path through a rectangular (can be square too) maze in which movements in all four directions are allowed and the rat can skip or break one wall. I have used recursion and backtracking below. Out of 5 test cases…
0
votes
1 answer

Generate all the strings of length n drawn from 0 ... k-1

This problem is from the book Data Structure and Algorithms Made Easy by Narasimha Karumanchi chapter Recursion and Backtracking. The algorithm which is given in the book is as follows: Let us assume we keep current k-ary string in an array…
0
votes
0 answers

Longest Increasing Subsequence (Javascript) Facebook Algo

I was trying to solve this problem with backtracking instead of DP...and ran into a problem that doesn't make sense to me. here is my code function solve(A) { let lp = 0; const path = []; const traverse = function (arr, i = 0) { if (i…
0
votes
1 answer

Sudoku solver with backtracking can't always detect multiple solutions

This is the code I wrote to check if there are multiple solutions to a KenKen puzzle (Similar to Sudoku). Technically it should return true if there are 2 solutions, but it doesn't appear to work because of a logic error in the algorithm. I can't…
user8908562
0
votes
0 answers

Scheduling algorithm in Racket (ASL)

I need to blend aspects of an arbitrary arity tree with generative recursion and backtracking in order to come up with a simple valid schedule. So far I have two structures, one that identifies the individual with her availability slots and maximum…
0
votes
2 answers

Min Jumps Array (Top-Down Approach)

Problem Statement : Given an array of non-negative integers, A, of length N, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Return the minimum number of…
0
votes
1 answer

How to solve a recursive Backtracking problem

I have a recursive Backtracking problem for school, and I do not understand how I would go about solving it. Given an array of integers, determine if it is possible to choose a group of those integers that add to a particular sum. Use a recursive…
JosephKidd
  • 23
  • 3
0
votes
0 answers

To determine the best country base on priority factor, prolog

Let's say we have this database: choice(marie, [peru,greece,vietnam]). choice(jean, [greece,peru,vietnam]). choice(sasha, [vietnam,peru,greece]). We want to know the best country based on the list of choice of each person, element 0 in the list…
0
votes
2 answers

Why this "Sudoku solver" algorithm does not work

I was trying to wrote a Sudoku solver algorithm, it should work like this: Pick a blank space, Choose a number and verify if is possible to have that number in that spot, if not choose another number, Recursively try to find a solution and if there…