32. Backtracking, N queens - Part A - Data Structures and Algorithms in Python
Students

Academic Programs

AI-powered learning for grades 8-12, aligned with major curricula

Professional

Professional Courses

Industry-relevant training in Business, Technology, and Design

Games

Interactive Games

Fun games to boost memory, math, typing, and English skills

32. Backtracking, N queens - Part A

32. Backtracking, N queens - Part A

The chapter discusses the concept of backtracking through the lens of the N Queens problem, where the challenge is to place N queens on an N x N chessboard such that no two queens attack each other. It explores how backtracking allows for systematic exploration of potential solutions by building candidate solutions incrementally and undoing steps when dead ends are reached. The chapter also highlights specific implementations for the eight queens problem and the necessary representations needed to track queen positions and attacked squares on the board.

12 sections

Sections

Navigate through the learning materials and practice exercises.

  1. 32.1
    Backtracking, N Queens

    This section introduces the concept of backtracking through the classic N...

  2. 32.1.1
    Introduction To Backtracking

    This section introduces backtracking as a systematic approach to solving...

  3. 32.1.2
    The Eight Queens Problem

    The Eight Queens Problem focuses on placing 8 queens on a chessboard such...

  4. 32.1.3
    Generalization To N Queens

    This section explores the N Queens problem, a classic backtracking algorithm...

  5. 32.1.4
    Systematic Approach To Solving N Queens

    The section covers the systematic approach of solving the N Queens problem...

  6. 32.1.5
    Recursive Solution For N Queens

    This section discusses the N Queens problem and explores how to use...

  7. 32.1.6
    Data Representation For N Queens

    This section explores the N Queens problem using backtracking techniques to...

  8. 32.1.7
    Handling Attacks On Squares

    This section discusses the process of systematically backtracking to solve...

  9. 32.2
    Implementation Of Backtracking

    Backtracking is a systematic method for solving problems by exploring all...

  10. 32.2.1
    Recursive Function For Placing Queens

    This section explores the recursive approach to solving the N Queens problem...

  11. 32.2.2
    Updating The Board State

    This section discusses the concept of backtracking in programming,...

  12. 32.2.3
    Efficient Tracking Of Attacks

    The section discusses efficient methods for tracking attacks in the N Queens...

What we have learnt

  • Backtracking is a systematic search method for solving problems by exploring possible solutions and undoing steps when necessary.
  • The N Queens problem demonstrates that placing queens on a chessboard requires careful consideration of their attacking positions based on the rules of chess.
  • The implementation of the N Queens solution can optimize board representation and track queen movements effectively.

Key Concepts

-- Backtracking
A recursive algorithmic technique that attempts to solve a problem by incrementally building candidates to the solution and abandoning those candidates ('backtrack') as soon as they are determined not to be valid.
-- N Queens Problem
A classic combinatorial problem that requires finding a way to place N queens on an N x N chessboard so that no two queens threaten each other.
-- Queen's Attack
In chess, a queen can attack any square horizontally, vertically, or diagonally from its position; thus, placing queens requires avoiding these attacked squares.

Additional Learning Materials

Supplementary resources to enhance your learning experience.