Knight's Tour

Move a knight so it visits every square of the board once.

Knight's Tour Visualization

Complexity

Time Complexity: O(8^(N²))
Space Complexity: O(N²)

Pseudocode

function tour(step, x, y):
  if step == N*N: return true
  for each knight move:
    if next cell is valid and unvisited:
      mark cell
      if tour(step + 1, nx, ny): return true
      unmark cell
  return false