Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

♟️ N-Queens Solver (BFS & DFS)

A Python-based solver for the classic N-Queens problem — implemented using both Breadth-First Search (BFS) and Depth-First Search (DFS).
This project compares the performance of the two algorithms and prints a sample solution on the board.

🎯 Developed as part of an AI fundamentals course by Ziyad Azzaz.


📋 Overview

The N-Queens problem asks:

Can you place N queens on an N×N chessboard so that no two queens attack each other?

This project:

  • ✅ Explores both BFS and DFS approaches
  • ✅ Measures time taken by each algorithm
  • ✅ Displays one possible solution on the board
  • ✅ Shows how constraint satisfaction works in AI search

🧠 Features

  • 🔎 BFS Search: Iterative search using queues
  • 🧭 DFS with Backtracking: Recursive and memory-efficient
  • ⏱️ Performance Timer: Measures execution time of each approach
  • 🎨 Board Display: Text-based board output with queen positions
  • 💻 CLI Interaction: User inputs N directly from terminal

📂 Files

File Name Description
n_queens_solver.py Main Python script
README.md Project documentation (this file)

👉 View the Full Code Here


▶️ How to Run

  1. Make sure Python is installed (>= 3.6)

  2. Clone this repo:

git clone https://github.com/ZiyadAzzaz/n-queens-solver.git
cd n-queens-solver
  1. Run the program:
python3 n_queens_solver.py

🧪 Example Output (N = 4)

Welcome to the N-Queens Solver!
═══════════════════════════════

Enter the number of queens (N): 4

Solving the 4-Queens problem...
──────────────────────────────

Search Results:
• BFS found 2 solutions in 1.85 ms
• DFS found 2 solutions in 0.42 ms

Sample Solution:
┌───┬───┬───┬───┐
│   │ Q │   │   │
├───┼───┼───┼───┤
│   │   │   │ Q │
├───┼───┼───┼───┤
│ Q │   │   │   │
├───┼───┼───┼───┤
│   │   │ Q │   │
└───┴───┴───┴───┘

Performance Comparison:
══════════════════════
│ Algorithm │ Time  │
══════════════════════
│ BFS       │ 1.85ms│
│ DFS       │ 0.42ms│
══════════════════════

Thanks for using the N-Queens Solver!
────────────────────────────────────
Made with ❤️ by Ziyad Azzaz 🧠 
(AI Course Project)

🛠️ Tech Stack

  • Language: Python
  • Modules: collections, time

💡 Educational Purpose

This project was built to demonstrate:

  • Basic constraint satisfaction
  • AI search strategies (DFS vs BFS)
  • Recursive and iterative problem solving
  • Performance trade-offs between search methods

👨‍💻 Author

Ziyad Azzaz
🔗 GitHub: ZiyadAzzaz


🪪 License

This project is open-source under the MIT License.

About

Python project to solve the N-Queens problem using BFS and DFS. Includes performance comparison and board visualization. Built as part of an AI course project by Ziyad Azzaz.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages