1 / 22

Backtracking Algorithm | Introduction To Backtracking | Data Structures

This presentation gives an introduction to backtracking that could help you prepare for competitive programming. This backtracking algorithm tutorial aims to help learn data structures and algorithms.<br> <br>This presentation will cover the following concepts:<br><br>1. Introduction<br>2. What is backtracking<br>3. N queens Problem<br>4. Implementation of N Queens Problem<br>5. Conclusion<br>

Simplilearn
Télécharger la présentation

Backtracking Algorithm | Introduction To Backtracking | Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Agenda

  2. Agenda What is Backtracking? N Queens Problem Implementation Conclusion

  3. Click here to watch the video

  4. What is Backtracking?

  5. What is Backtracking? Backtracking is an algorithmic approach to solving a problem in a different way. To illustrate the issues, it use a recursive method. To solve an optimization problem, we might state that backtracking is required.

  6. N Queens Problem

  7. N Queens Problem We will start with the left most column

  8. N Queens Problem We will check if all the queens have been placed or not.

  9. N Queens Problem Now we will try every row in this column.

  10. N Queens Problem Now we will try every row in this column. If the queen can be safely placed in this row, then we will mark it as part of the solution.

  11. N Queens Problem Now we will try every row in this column. If the queen can be safely placed in this row, then we will mark it as part of the solution. Then we will recursively check if placing queen there will lead to the complete solution. If yes, then return true.

  12. N Queens Problem Now we will try every row in this column. If the queen can be safely placed in this row, then we will mark it as part of the solution. Then we will recursively check if placing queen there will lead to the complete solution. If yes, then return true. If False, then we will backtrack and try different row, and repeat these steps back.

  13. N Queens Problem In case if all the rows have been tried and nothing worked then return false to trigger backtracking

  14. Implementation

  15. Conclusion

  16. Conclusion It is very easy to implement and contains less LOC . Most of the back tracking codes are generally few lines of recursive function code.

  17. Conclusion It has a large space complexity because we are using recursion, so function information is stored on stack.

  18. Conclusion It is very time inefficient in lot of cases when branching factor is large

  19. Conclusion We can solve many problems like the knight’s tour, N queens, Rat in the maze, subset sum problem and so on

More Related