• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

8 Queen Problem

June 21, 2011 by ProjectsGeek Leave a Comment

 

 

 

8 Queen Problem
Aim: Implementation of 8 queen problem( Non recursive implementation) using

backtracking strategy

Objective: To study and understand the concept of backtracking.

Theory:

 

 

 

Backtracking

 

General method-

• Useful technique for optimizing search under some constraints

• Express the desired solution as an n-tuple (x1, . . . , xn) where each xi 2 Si, Si being a finite set

• The solution is based on finding one or more vectors that maximize, minimize, or satisfy a criterion function P(x1, . . . , xn)

• Sorting an array a[n]

– Find an n-tuple where the element xi is the index of ith smallest element in a

– Criterion function is given by a[xi] _ a[xi+1] for 1 _ i < n

– Set Si is a finite set of integers in the range [1,n]

• Brute force approach

– Let the size of set Si be mi

– There are m = m1m2 · · ·mn n-tuples that satisfy the criterion function P

– In brute force algorithm, you have to form all the m n-tuples to determine the optimal solutions

• Backtrack approach

– Requires less than m trials to determine the solution

– Form a solution (partial vector) and check at every step if this has any chance of success

– If the solution at any point seems not-promising, ignore it

– If the partial vector (x1, x2, . . . , xi) does not yield an optimal solution, ignore mi+1 · · ·mn possible test vectors

even without looking at them

• All the solutions require a set of constraints divided into two categories: explicit and implicit constraints

Definition 1 Explicit constraints are rules that restrict each xi to take on values only from a given set.

– Explicit constraints depend on the particular instance I of problem being solved

– All tuples that satisfy the explicit constraints define a possible solution space for I

– Examples of explicit constraints

_ xi _ 0, or all nonnegative real numbers

_ xi = {0, 1}

_ li _ xi _ ui

Definition 2 Implicit constraints are rules that determine which of the tuples in the solution space of I satisfy the

criterion function.

– Implicit constraints describe the way in which the xis must relate to each other.

• 8-queens problem

 

 

 

– Place eight queens on an 8 × 8 chessboard so that no queen attacks another queen

Backtracking

1

2

3

4

5

6

7

8

1

Q

2

Q

3

Q

4

Q

5

Q

6

Q

7

Q

8

Q

– Identify data structures to solve the problem

_ First pass: Define the chessboard to be an 8 × 8 array

_ Second pass: Since each queen is in a different row, define the chessboard solution to be an 8-tuple (x1, . . . , x8),

where xi is the column for ith queen

– Identify explicit constraints

_ Explicit constraints using 8-tuple formulation are Si = {1, 2, 3, 4, 5, 6, 7, 8}, 1 _ i _ 8

_ Solution space of 88 8-tuples

– Identify implicit constraints

_ No two xi can be the same, or all the queens must be in different columns

· All solutions are permutations of the 8-tuple (1, 2, 3, 4, 5, 6, 7, 8)

· Reduces the size of solution space from 88 to 8! tuples

_ No two queens can be on the same diagonal

– The solution above is expressed as an 8-tuple as 4, 6, 8, 2, 7, 1, 3, 5

Other Projects to Try:

  1. Prim’s Algorithm , Minimum Cost of Spanning Tree
  2. N queen problem code in C Language

Filed Under: Design and Analysis of Algorithms

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy