Skip to main content
Filter by
Sorted by
Tagged with
2 votes
0 answers
136 views

I'm developing a backtracking function to solve a maze given by a matrix of 0 and 1. The problem is that, for small matrices, it correctly finds the shortest path, but for matrices 15x15 or larger, it ...
Ingenieria Vichi's user avatar
0 votes
1 answer
66 views

A permutations problem (LeetCode), which finds the permutations of an array [1,2,3], is returning an empty array through a backtracking recursive function. The console prints out the following: Input ...
Will Sherman's user avatar
1 vote
1 answer
90 views

Reading up on backtracking led me to a page on geeksforgeeks.org about solutions to the n-queens problem. The first solution is introduced as the "naive approach" that generates all possible ...
retpoline's user avatar
0 votes
1 answer
78 views

Concerning Javascript, I've been trying to understand backtracking lately and it's really confusing. Specifically, I've been trying to understand the permutation problem, which when given an array, we ...
ContravariantMind's user avatar
4 votes
1 answer
79 views

Q. How do I decide whether to pass i+1 or j+1 in the recursive call when constructing a backtracking function from a state-space tree diagram? Key Insights I develop from the state-space tree diagram: ...
Mr. Ghosh's user avatar
0 votes
0 answers
58 views

Background: I have recorded navigation trajectory positional x,y and its time point (50hz) data from a virtual reality navigation in an empty room. Problem: I want to calculate how much the navigation ...
Michael Liang's user avatar
1 vote
1 answer
52 views

I try to solve Knight tour problem with python and backtracking, but the code doesn't respond likely I want... This is my code in python: import random board = [ [0,0,0,0,0,0], [0,0,0,0,0,0], ...
Sina Dehghani's user avatar
0 votes
1 answer
88 views

Why the time complexity of generating power set of given array is O(n * 2^n). The solution which I created or even the solution which is shared on leetcode runs 2^n times. 1 loop to generate 1 subset. ...
Onki's user avatar
  • 2,115
0 votes
0 answers
58 views

I wanted to check the part of unidec softwares code that converts agilent .d folders to txt file so i opened the agilent.py file and changed the path to my desired file after running the command it ...
Hulkbuster's user avatar
0 votes
1 answer
151 views

I am working on a task to find the largest independent set in a graph. After researching various approaches, I found that backtracking is often recommended, but it has exponential time complexity, ...
Sibi Varshan's user avatar
-2 votes
1 answer
82 views

class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> combine(int n, int k) { List<Integer> list = new ...
user27919292's user avatar
-4 votes
1 answer
232 views

The following is a Leetcode problem: 473. Matchsticks to Square (https://leetcode.com/problems/matchsticks-to-square/description/) Problem Statement You have an array, matchsticks, of size n, with ...
monre's user avatar
  • 135
-1 votes
1 answer
174 views

I am working on an optimized Sudoku solver. The basic idea of backtracking remains, though I have added forward checking. The domain (what numbers can be set into a cell) is stored for every cell. ...
Eric's user avatar
  • 25
0 votes
0 answers
47 views

As my previous post outlined, I am making a puzzle solver, however, my puzzles don't contain jigsaw pieces but normal rectangles instead. My initial post was asking about an algorithm that I can use ...
M3mber's user avatar
  • 53
3 votes
1 answer
145 views

I think that I understand how Prolog uses unification and backtracking to find the first match. However I'm having a hard time trying to understand what does it do when it is asked to "redo" ...
Tim's user avatar
  • 7,614
0 votes
2 answers
102 views

def combination(n,k): combi=[] def backtrack(start,comb): print(comb) if len(comb)==k: combi.append(comb.copy()) return for ...
data_geek's user avatar
1 vote
1 answer
91 views

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins that you need to make ...
Ashna kohli's user avatar
6 votes
1 answer
218 views

Though I'm aware of the basic recursive N queens solution, I'm trying to learn more about backtracking by studying and implementing Knuth's "Algorithm B (Basic backtrack)" for the case of ...
MaroonSphinx's user avatar
1 vote
1 answer
310 views

I am building the logic to the Leetcode - Combination Sum problem. Here is a link to the problem.The problem states: Given an array of distinct integers candidates and a target integer target, return ...
vikram sah's user avatar
1 vote
1 answer
175 views

Problem Statement: Given a N*N board with the Knight placed on the first block of an empty board. Moving according to the rules of chess knight must visit each square exactly once. Print the order of ...
MathMan's user avatar
  • 237
0 votes
0 answers
75 views

It seems the code I wrote doesn't backtrack properly and i have no idea where the backtracking goes wrong. Hitori is an "reverse" Sudoku. You are given a matrix filled with numbers and have ...
Alex's user avatar
  • 1
2 votes
1 answer
155 views

I was attempting the word search problem here on leetcode. Leetcode seems to give me an error for the two test cases: board = [["a","a"]], word = "aa" and for : board = [[...
MathMan's user avatar
  • 237
1 vote
1 answer
93 views

I was attempting a recursive solution to the n queens problem. Please take a look at this code: def solve(n,chess_arr,forbidden_cells=[]): print("1.",n,chess_arr,forbidden_cells) if n&...
MathMan's user avatar
  • 237
0 votes
1 answer
68 views

I have written a code to recursively remove the adjacent duplicates from a string class Solution{ String rremove(String s) { // code here StringBuilder sb = new StringBuilder(); int i ...
GlidingSwords997's user avatar
0 votes
0 answers
37 views

This is a minimal reproducible code, so please do not concern about the meaningfulness of the code. I want to input a list with one element, and return once it grows to length of 5. So I use a ...
lambda's user avatar
  • 25
0 votes
1 answer
108 views

I have a Prolog program with two predicates, rr and p, each with its own set of rules and facts. When querying these predicates with specific inputs, I noticed that Prolog automatically backtracks in ...
Cardstdani's user avatar
  • 5,251
0 votes
0 answers
41 views

public static void Queens(char b[][],int row) { if(row==b.length){ print(b); return; } for(int j=0;j<b[0].length;j++){ b[row][j]='Q'; ...
Astitva Shukla's user avatar
0 votes
1 answer
112 views

I’m doing leetcode 79 C++ solution, where you need to find word in 2D matrix. I’m doing it with backtracking class Solution { private: vector<vector<char>> matrix; //Пример ...
MrLeyt1125's user avatar
-1 votes
1 answer
62 views

I dont quite understand why have we used .clone() method when we have a second for loop to restore the letterCount.And when i'm runnig this code without .clone() method its giving me the wrong answer? ...
jonshrey's user avatar
1 vote
1 answer
104 views

I have got this maze of 2d matrix. '@' indicates the start and '#' indicates the end. 0 means the path is blocked and 1 means that you can pass through. The program needs to solve the maze and print ...
chaos's user avatar
  • 13
1 vote
1 answer
79 views

I have been following a playlist of Java for data structures and algorithms and I have come across the topic of Backtracking in which a board is given to you along with starting point (0,0) and end ...
Aadit Baldha's user avatar
1 vote
1 answer
80 views

I need help making a python algorithm. I want to make a grid and place a "x" on cells based on certain rules. The grid is 15 rows and 100 columns. There should only be 1 "x" per ...
Shawn's user avatar
  • 11
-5 votes
1 answer
122 views

Question Given an m x n board of characters and a list of strings words, return all words on the board. Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells ...
Divik's user avatar
  • 13
1 vote
0 answers
60 views

In a school, I have multiple classes. Each class could be divided into breakout rooms of 3 or 4 students randomly. We want to avoid duplicate breakout rooms at least we want more randomness and ...
sahil's user avatar
  • 63
1 vote
1 answer
72 views

This question is slightly inspired by the Infinite Craft neal.fun game. I've managed to build a graph structure representing the alchemy additions. For example, { "Water": { "Fire":...
Rahul's user avatar
  • 1,276
0 votes
1 answer
78 views

Here is the code: public class sudoku { public static void printSudoku(int sudoku[][]){ for(int i = 0; i < sudoku.length; i++){ for(int j = 0; j < sudoku[i].length; j++){ ...
Jaspreet Sharma's user avatar
-1 votes
1 answer
76 views

i' am unable to make recursion tree i saw many videos on this question but nobody is telling that after first left most leaf node completion how the full recursion is made cause after there will two ...
Sachin Nigam's user avatar
1 vote
0 answers
67 views

Which to use and when? And what are the advantages of one approach over the other? Permutation brute force is the one in which at each recursion step, we can enter any of the array elements. If ...
Someone's user avatar
  • 31
1 vote
1 answer
94 views

Here is my code. using namespace std; int ans = 0; string il[8]; //squares which cannot contain any queens void quen(int x, int y, bool table1[15],bool table2[15], bool table3[8]){ if(il[y][x]!='*'...
Boran Alp Yalcin's user avatar
2 votes
1 answer
349 views

Given an M*N matrix, I want to calculate the total number of possible paths from the upper-left cell (0,0) to the lower-right cell (m-1, n-1). Possible movements include up, down, right, and left. A ...
BeeP's user avatar
  • 21
1 vote
0 answers
89 views

Im currently trying to program a Backtrack resolver using the mantaining arc consistency technique to do inferences on the domains of the other variables but Im stuck because it seems like I cant do ...
eliainnocenti's user avatar
0 votes
1 answer
71 views

I'm currently trying to program a backtrack resolver for an university project. It should resolve the job scheduling problem. I created 2 classes to do this: JobSchedulingProblem and Constraint. class ...
Babboboncia's user avatar
0 votes
1 answer
80 views

I'm using the backtracking algorithm to solve the classical. Leetcode permutation problem. Given an array nums of distinct integers, return all the possible permutations. You can return the answer in ...
Junjie Yu's user avatar
1 vote
0 answers
50 views

I'm working on a JavaFX project where I need to manage a 3D grid representing a Tetris-like game environment. My current implementation involves multiple nested loops and array manipulations, which I ...
Magdy Fares's user avatar
2 votes
0 answers
127 views

I have the following backtracking solution to chess endgames with D=3 figures on the board. I should have obtained white king to move on Kc2, but I'm getting Qh3h8. I have printed the print(board....
user22758952's user avatar
0 votes
0 answers
87 views

I am currently attempting to write a Chronological Backtracking Algorithem for a sudoku solver. I have several positions stored as FlexiblePositions, which is represented as two integer in an array. ...
Hendrik's user avatar
  • 47
-1 votes
1 answer
52 views

I'm new to Java and I'm trying to build a sudoku solver programm using backtracking and an int[][] matrix. Function usage: isSafeSudoku() this function checks whether the digit (from 1 to 9) is safe ...
Vipul's user avatar
  • 1
-1 votes
1 answer
94 views

I am having trouble understanding a backtracking solution. I am new to algorithms and recursion. This is a leetcode problem. Leetcode 46. class Solution: def permute(self, nums: List[int]) -> ...
julie's user avatar
  • 1
0 votes
1 answer
66 views

So here's the problem. For a given n we need to generate all valid parenthesis. For e.g, for n=2 the possible output will be ()(), (())) So I tried solving using recursion and backtracking. I take two ...
ABGR's user avatar
  • 5,263
1 vote
1 answer
188 views

Im trying to understand how backtracking works on php. I understand the theory but then I dont understand the code. This is an easy example: function permute($nums) { $result = array(); ...
Raluido's user avatar
  • 31

1
2 3 4 5
33