More Related Content
Similar to Dynamic Programming Algorithm to Solve N-Queens Problem
Similar to Dynamic Programming Algorithm to Solve N-Queens Problem (17)
More from Onkar Nath Sharma
More from Onkar Nath Sharma (6)
Dynamic Programming Algorithm to Solve N-Queens Problem
- 7. AlgorithmNextValue(k)
{
repeat
{
x[k]:=(x[k]+1)mod(m+1);//Nexthighestcolor
if(x[k]=0)thenreturn;//Allcolorshavebeenused.
forj:=1tondo
{//checkifthiscolorisdistantfromadjacentcolors.
if((G[k,j]!=0)and(x[k]=x[j]))
//if(k,j)isandedgeandifadj.verticeshavethesamecolor.
thenbreak;
}
if(j=n+1)thenreturn;//Newcolorfound
}untill(false);//Trytofindanothercolor.
}