N-Queens Problem - Backtracking

Поделиться
HTML-код
  • Опубликовано: 30 ноя 2024

Комментарии • 34

  • @madhubhargava5049
    @madhubhargava5049 8 лет назад +2

    This is probably one of the best explanations on N-Queens Problem.
    Thank You. Have a great day.

  • @TheBlvision
    @TheBlvision 6 лет назад +1

    You have my utmost appreciation for such a thorough explanation of this n queens problem - which has puzzled me for years since I first knew this problem. I truly believe that if I could understand the thoughts and technique of solving n queens problem, I would get the least sense of programming, and I might really have a chance to become a programmer.
    many thanks for this tutoring video. many many thanks

  • @shawnscientifica6689
    @shawnscientifica6689 7 лет назад +6

    FYI to ALL: There is a mistake in the video. In the else statement under the backtrack call, you need to unmark your last answer. This is the very heart of backtracking (unmarking) if you're not unmarking you're likely doing it wrong unless it is hypothetical marks on a recursive system stack (you pretend to Mark and recursively go down)

  • @kevintang5508
    @kevintang5508 4 года назад +3

    Anybody noticed that what the graphics show are not queens... but kings?

  • @santoshkumar-xh6fk
    @santoshkumar-xh6fk 9 лет назад +2

    Dear CS Breakdown..After searching for 2 days i landed to your channel.
    You have explained very well this problem. I had difficulty in the backtracking part of the logic.
    Thank you so much...
    Can you please make vids for the DP as well

  • @lifeoutdare
    @lifeoutdare 6 лет назад +8

    i did not understand how this code goes back to previous row when all the columns in the current row is unsafe ??

  • @yasinrasin
    @yasinrasin 3 года назад

    Thanks for this tutoring video with clear explanations.

  • @RoylanMartinez
    @RoylanMartinez 5 лет назад

    what you put in the video actually is the king

  • @chamnil8666
    @chamnil8666 4 года назад

    Thank you so much.Have a blessed day.

  • @21stcenturydigitalje
    @21stcenturydigitalje 8 лет назад

    Instead of storing the queens position in a matrix you can just use a list that stores each queens row and column, then your queensSafe function becomes much more efficient:
    forEach(q in placedQueens) {
    if (q.col == col || (abs(q.row - row) == abs(q.col-col)) {
    return false;
    }
    }
    return true;

  • @ambarishgangulyv176
    @ambarishgangulyv176 7 лет назад

    Hey, Sir... your explanations are awesome and easily understood... plz add more videos on NP completeness, approximation algorithms, Largest Common Subsequence... etc.. It would be really helpful.... if you consider doing more videos on Design and Analysis of Algorithms.

  • @eddiel533
    @eddiel533 8 лет назад

    In your efficient QueenSafe function I think the for loop should be for(i=1 to row) not for(i=1 to col).

  • @awestruckperson
    @awestruckperson 8 лет назад +2

    How does the algo remove the true value which has been been but are not there in the final solution?

  • @samkumargupta2536
    @samkumargupta2536 8 лет назад

    Thanks for uploading such conceptual tutorials....

  • @shenshenliang2626
    @shenshenliang2626 7 лет назад

    Is there a mistake in 3:32 for the last for loop? As a counter example, (7,2) will only check 3 grids with the given code. I believe the last for loop should be like: for(i=row+reset, j=col-reset; i>0 && j

  • @chintanshah9561
    @chintanshah9561 8 лет назад

    Very well explained. Subscribed!

  • @rishabhshirke1175
    @rishabhshirke1175 8 лет назад

    at 10:36,you said it is safe to place queen at (3,2) after checking with your original queensafe function(not the optimized one). according to it,there is no queen In the same row and column.then we move to the reset part,for checking the diagonals.here the reset is 1. therefore it will start it's diagonal check from (2,1) to (4,3).after that it will check the other diagonal from (2,3),why it is not supposed to start from (1,4)?

  • @dammyd9951
    @dammyd9951 8 лет назад

    Hey man. My algorithm backtracks but the previous queen is still stored in its location. Im not sure how to remove it. I stopped at time: 10:03

    • @ultimatehuzefa
      @ultimatehuzefa 8 лет назад

      Sir there might be some error in your program...bcoz when the program backtracks.. It automatically discards the unnecessary values

  • @joegame4576
    @joegame4576 8 лет назад

    is backtracking the same as hill climbing? if different, what would the
    algorithm look like if hill climbing was used instead of backtracking?

  • @BoudieBatsnikov
    @BoudieBatsnikov 8 лет назад

    where can i find the whole program?

  • @regexp8525
    @regexp8525 8 лет назад

    Are backtracking algorithms a NFA?

  • @pandemade3875
    @pandemade3875 5 лет назад

    can anyone explain to me how did he made it more efficient?

  • @prantaksingh8140
    @prantaksingh8140 7 лет назад

    sir pls show it for 4*4 chess board

  • @rafaaaaaaa1
    @rafaaaaaaa1 8 лет назад +1

    you guys are great!!!

  • @BongelaMnguni
    @BongelaMnguni 7 лет назад

    Why are you using Kings instead of Queens? Unlike a Queen, a King can only attack what it is touching

  • @h3nnn4n
    @h3nnn4n 9 лет назад

    When you say optimal solution, what do you mean? Aren't all feasible solutions for the n-queen problem also optimal? There is no such thing as a non optimal solution for the n-queen problem.
    Nice video btw.

    • @CSBreakdown
      @CSBreakdown  9 лет назад +5

      Renan Silva Hi Renan, thanks for watching. If you didn't employ backtracking, the algorithm would attempt every possible configuration, even bad ones, to completion, which is unnecessarily computationally expensive.
      With backtracking, it checks on every queen placement, and if it doesn't work, it stops, goes back a level, and tries again. You can think of it almost like tree branches with each branch from the root being one of 4 of the first queens possible placements. Not using backtracking would ensure that the branches are all 4 nodes deep (assuming a 4x4 board).
      With backtracking, only the "placements that work", aka the optimal placements are 4 nodes deep, other branches are not. This saves the computer a fair amount of computation time as it no longer needs to create trees that are 4 (or n) nodes deep. It also can save a significant amount of space as well.
      On a 4x4 board, the savings is trivial, but we're assuming a board of size n, and we must assume that n is as big as the number of all known atoms in the universe (really freaking big!).
      So the concept of backtracking helps us find 'placements that work' without attempting every permutation to completion.

    • @nirajgaonkar7669
      @nirajgaonkar7669 8 лет назад +1

      how it backtracks?
      there is no code satisfying about backtracking

  • @raunakmuz
    @raunakmuz 9 лет назад

    thanks

  • @abhinavborkar3676
    @abhinavborkar3676 9 лет назад

    bravo !!

  • @shahriarhaqueabir7687
    @shahriarhaqueabir7687 8 лет назад

    thanks :)

  • @kaushiksivakumar2036
    @kaushiksivakumar2036 9 лет назад

    CSBreakdown Awesome!

  • @taihungau8696
    @taihungau8696 8 лет назад +2

    those are kings not queens noob