I am trying to print 8*8 chess board n queen problem


i am trying to print 8*8 chess board having 8 queen but i am not able to write correct recursive case;
please debug my code and tell me what mistake i am doing hare

@bishtmanish786

  1. Line No. 62 - Check only for the row. if(row == 8) …8 , not 7 . No need to check for column or your code will never reach the base condition.
  2. In the loop beginning in Line No. 79 , you should be trying to check over the column rather than the rows or your code will never terminate. Change the if condition in Line No. 80 to
    if(is_safe(arr,row,i))
    from
    if(is_safe(arr,i,collum))
  3. Also write
    arr[row][i]=1;
    instead of
    arr[i][collum]=1;
    in Line No. 81
  4. Make similar change at Line No. 92 as well ,
    arr[row][i]=0;
    instead of
    arr[i][collum]=1;

@tarunluthra i have made those changes but this code still not working please debug it once again
updated code-https://ide.codingblocks.com/s/123494

@bishtmanish786
I asked you to remove the column check condition altogether.
In your updated code , go to Line No. 62 , and modify the if condition to
if(row==8)

Do not check for column at all.

@tarunluthra thanks this code is working fine now https://ide.codingblocks.com/s/123501 but can you tell me what was wrong with (collum==8 ) i dint understand why this condition was wrong. we will print out chess board when we reach out of chess beard right?

@bishtmanish786
Our approach to solve this problem is to move row by row. As we reach row = 8 ( which is outside our board as rows are numbered from 0 to 7 ) , we have completed our task of placing N queens. Since we only move to the next row , we should only check for the last row and not the column. If we put the condition for row and both column , we are implying that the last queen must be placed at the bottom right cell only which is not correct as the queen may be placed anywhere in the last row depending upon the rest of the configuration.

thanks very much sir
please resolve this doubt too DP problem Longest Increasing subsequence

@bishtmanish786
That doubt has been taken up by another TA who is resolving it. He will help you out for sure and you can ask any doubts regarding that issue from him.
Let me know if you have any further issues regarding this doubt or kindly mark this doubt as resolved in your Doubts Section.

1 Like