Skip to content

Commit

Permalink
Add Hamiltonian cycle.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed May 17, 2018
1 parent 569c6ae commit d2c6d14
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function hamiltonianCycleRecursive({
cycle: currentCycle,
});

// BACKTRACKING.
// Remove candidate vertex from cycle path in order to try another one.
currentCycle.pop();
}
Expand Down
1 change: 1 addition & 0 deletions src/algorithms/uncategorized/n-queens/nQueens.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function nQueensRecursive(solutions, previousQueensPositions, queensCount, rowIn
// Try to place all other queens as well.
nQueensRecursive(solutions, queensPositions, queensCount, rowIndex + 1);

// BACKTRACKING.
// Remove the queen from the row to avoid isSafe() returning false.
queensPositions[rowIndex] = null;
}
Expand Down

0 comments on commit d2c6d14

Please sign in to comment.