Sitemap

Member-only story

Intro — Python Algorithms: Eight Queens Problem

15 min readSep 2, 2024

--

Problem Statement

The Eight Queens Problem is a classic example of a combinatorial puzzle in computer science. It involves the challenge of placing eight queens on an 8x8 chessboard in such a way that no two queens can attack each other. To understand the problem fully, let’s first explore how a queen moves in chess.

How The Queen Moves in Chess

The queen can move any number of unoccupied squares in a straight line — vertically, horizontally, or diagonally — combining the movement capabilities of both the rook and bishop. The diagram below shows all the possible moves (indicated by orange dots) that a queen can make on a chessboard.

Figure 1 — Queen at Center

At its optimal position, such as the center of the board depicted in Figure 1, a queen can control up to 27 squares. Here’s the breakdown:

  • Vertical: 7 squares (excluding the square it occupies)
  • Horizontal: 7 squares (excluding the square it occupies)
  • Diagonals: 13 squares (excluding the square it occupies)

Our Goal

--

--

David Liang
David Liang

Written by David Liang

Full Stack AI/Data Engineer - Architecting integrated solutions across full-stack development and advanced AI/data engineering.