interesting because just the other day I wrote something to get all 92 solutions for 8x8 "n queens" problem in a little under 3 sec. I also used to play chess seriously, and my coach once gave me this exercise to find a few working configurations.
I would advise against blindly placing all queens and then checking if "secure" -- way too many combinations to go through. Your problem here might be that it is possible to place 7 queens, and the 8th one might have no place to go. At this point in your algorithm, doesnt "count" become 8 anyway, and tries to return true? I went with the algorithm to place the rooks on the board, 8! permutations, one on each row, and then check all diagonals. This can be limited to even fewer iterations, but it was fast enough for me. hope this helps, icy` On Sep 1, 3:30 pm, mc2 verma <qlearn...@gmail.com> wrote: > hey guys , > > I am trying to solve 8-queens problem using backtracking. Here is my algo. > Could someone please tell me what is wrong in this code?? > > bool queen(int p,int count , int position[][]) > { > if(count == 8) return true; > > for(int i=p,i<8;i++) > for(int j=0;j<8;j++) > if(marked(i,j) == false ) // finding secure position on board > { > markboard(i,j); // if found any secure position then > mark all board positions which are in range of queen. > position[count][count]={i,j}; //save position for final answer > count++; > if(queen(p+1,count,position[][]) == true) > return true; > } > > > > > > > > } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.