• 1 day ago
Transcript
00:00Next, there is another optimization that exists in N-queen, another form that exists in N-queen
00:06It is that to print only one solution
00:08What have I done? I had printed all chessboards
00:11Now my question is that either I will remove the solution or I will not remove the solution
00:18If there is, then I will print one solution
00:21I will modify N-queen in this way
00:24So I have a question to check if the problem can be solved and print only one solution to N
00:30-queen's problem
00:31Now I will change the same code inside this
00:35What do I do in this way?
00:37What do I do every time?
00:39I would check for the queen
00:40Is it safe to place it on the board?
00:44Is it safe to place it on the board?
00:48After that, I would perform some steps
00:49Usually, what were my steps?
00:52I would place it on the board
00:54I would call it on the board
00:56Then I would call N-queen
00:57After that, I would place it on the board
01:00I would replace it on the board
01:02What do I do?
01:04I will check it on the board
01:06I will place it on the board
01:07Then I will check it on the board
01:11I will check it on the board
01:12And every time the solution exists
01:14I will return the recursive function
01:16This time I will return the type of boolean
01:18So I will return the function of N-queen
01:20The return type is boolean type
01:24So if I know it here
01:26The solution exists for N-queen
01:29Then I will return it on the board
01:33If I have placed it on the board
01:35I will place it on the board
01:36Now I will check for N-queen
01:38If the solution exists or not
01:40N-queen exists for N-queen
01:43I have placed it on the board
01:44So the solution exists and placed it on the board
02:02Then I will check the main function
02:03After that, I will not check new solutions
02:06Why did I check all the solutions
02:09Because I had to print all possible solutions
02:11But now because I only need a solution
02:13I will return the main function
02:18Now I will return the main function
02:20Now let me see the modifications in this
02:21This was my N-queen code
02:23What did I do every time?
02:25I was checking what is safe
02:26I would place it on the board
02:28I would check it on the board
02:28Here I would check it on the board
02:30I would do it on the board
02:33I would place it on the board
02:33I will check it on the board
02:35Before I will make this function
02:35I will make the boolean type
02:36It is a boolean type function
02:39What will happen here?
02:40As I have reached this step
02:41With the count plus plus
02:42I will return it on the board
02:44The solution is possible
02:45What will happen here?
02:53If I have placed N-queen
02:56Then I will return it on the board
03:01If I have placed false here
03:03I will place it on the board
03:04I will place it on the board
03:05Only two lines of change
03:07One will change the return
03:08One will return true
03:10And one will return true
03:12Let me ask that
03:13No possible solution is possible
03:15Which can be true
03:15So one time
03:18False will return it on the board
03:19False return
03:20So this is my complete N-queen
03:22Now in the main function
03:23When I will call the N-queen
03:30In this case
03:31I will print it on the board
03:33Solution is possible
03:35And I will print it on the solution
03:37How will I?
03:38I will call the print board
03:40Which I will pass the board
03:41Else
03:45Solution is
03:48Not possible
03:50Let's do this
03:51Save and Run
03:52Run
03:52For N is equal to 4
03:54For N is equal to 4
03:59For N is equal to 4
04:00For N is equal to 4
04:00Printed solution is possible
04:01And I will have my possible solution
04:03Printed
04:04This time
04:04There are two prints
04:04This time
04:05One is printed
04:06Because one is printed
04:07As I have got a solution
04:10As I have got here
04:10What did I do?
04:11Unplaced
04:11It has not found a new solution
04:12It has returned here
04:14And what is the solution
04:15We have printed here
04:16In the main function
04:17Here
04:18Printed
04:19Now
04:19If I pass N is equal to 2
04:20Then
04:21No solution
04:22Will exist
04:22In this case
04:23Printed
04:25Solution is
04:26Not possible
04:27In this case
04:28To solve N queens
04:28We have 3 different ways
04:30We have printed
04:31The first way
04:32We have printed all possible solutions
04:34The second way
04:35We have counted possible solutions
04:37And the third way
04:38What did we do?
04:40We have checked
04:40That the solution exists
04:41Or not
04:42And if it exists
04:44In this case
04:45I have printed one solution
04:45Well
04:46One solution
04:46I have printed one solution
04:48I have printed one solution
04:48The so is a solution
04:48So that was even