From d2c6d14acd1a941e7153c33f441d73162c2dbcbb Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Thu, 17 May 2018 08:08:29 +0300 Subject: [PATCH] Add Hamiltonian cycle. --- src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js | 1 + src/algorithms/uncategorized/n-queens/nQueens.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js b/src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js index 9f73a564..84562615 100644 --- a/src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js +++ b/src/algorithms/graph/hamiltonian-cycle/hamiltonianCycle.js @@ -91,6 +91,7 @@ function hamiltonianCycleRecursive({ cycle: currentCycle, }); + // BACKTRACKING. // Remove candidate vertex from cycle path in order to try another one. currentCycle.pop(); } diff --git a/src/algorithms/uncategorized/n-queens/nQueens.js b/src/algorithms/uncategorized/n-queens/nQueens.js index f0e7eb09..d96748d4 100644 --- a/src/algorithms/uncategorized/n-queens/nQueens.js +++ b/src/algorithms/uncategorized/n-queens/nQueens.js @@ -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; }