Analysis and design of algorithm

Slides:



Advertisements
Similar presentations
Informed search algorithms
Advertisements

Informed search algorithms
Local Search Algorithms Chapter 4. Outline Hill-climbing search Simulated annealing search Local beam search Genetic algorithms Ant Colony Optimization.
Iterative Deepening A* & Constraint Satisfaction Problems Lecture Module 6.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Eight queens puzzle. The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard such that none of them are able to capture.
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Backtracking What is backtracking?
CS420 lecture ten BACKTRACK. Solution vectors In optimization problems, or more general in search problems, a set of choices are to be made to arrive.
CSE 221/ICT221 Analysis and Design of Algorithms Lecture 06: CSE 221/ICT221 Analysis and Design of Algorithms Lecture 06: Analysis of Algorithm using List,
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
CSE 143 Lecture 17 More Recursive Backtracking reading: "Appendix R" on course web site slides created by Marty Stepp and Hélène Martin
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Contents of Chapter 7 Chapter 7 Backtracking 7.1 The General method
CS 312: Algorithm Analysis Lecture #32: Intro. to State-Space Search This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported.
Announcements This Wednesday, Class and Labs are cancelled! The last lab is due this Wednesday … how many people are planning on doing it? Finally posted.
Data Structures Using C++ 2E1 Recursion and Backtracking: DFS Depth first search (a way to traverse a tree or graph) Backtracking can be regarded as a.
Sudoku Jordi Cortadella Department of Computer Science.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
CPS Backtracking, Search, Heuristics l Many problems require an approach similar to solving a maze  Certain mazes can be solved using the “right-hand”
CSE 143 Lecture 18 More Recursive Backtracking slides created by Marty Stepp
Backtracking & Brute Force Optimization Intro2CS – weeks
© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
CompSci Problem Solving: Sudoku  Rules of the Game Sudoku is played with a 9 by 9 "board" consisting of nine 3 by 3 sub-boards. The symbols 1 -
1 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 CSC384: Intro to Artificial Intelligence Backtracking Search I ● Announcements.
CSE 143 read: 12.5 Lecture 18: recursive backtracking.
1 Tirgul 11: Recursion & Backtracking. 2 Elements of a recursive solution (Reminder) A base case that is so simple we need no computation to solve it.
Various Problem Solving Approaches. Problem solving by analogy Very often problems can be solved by looking at similar problems. For example, consider.
CSG3F3/ Desain dan Analisis Algoritma
Problem Solving: Brute Force Approaches
Backtracking, Search, Heuristics
CSSE 230 Day 25 Skip Lists.
Intro to Computer Science II
CSCI 104 Backtracking Search
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Data Structures and Algorithms
Local Search Algorithms
Constraint Satisfaction Problem
The "8 Queens" problem Consider the problem of trying to place 8 queens on a chess board such that no queen can attack another queen. What are the "choices"?
CSE 143 Lecture 19 More Recursive Backtracking
CS 188: Artificial Intelligence
Using a Stack Chapter 6 introduces the stack data type.
Recursion Copyright (c) Pearson All rights reserved.
Problem Solving: Brute Force Approaches
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Using a Stack Chapter 6 introduces the stack data type.
Jordi Cortadella Department of Computer Science
Number Theory.
Number Theory.
Chapter 6 Planning-Graph Techniques
adapted from Recursive Backtracking by Mike Scott, UT Austin
The N-queens problem Team: 404 brain not found
Using a Stack Chapter 6 introduces the stack data type.
Using a Stack Chapter 6 introduces the stack data type.
Exercise: Dice roll sum Write a method diceSum similar to diceRoll, but it also accepts a desired sum and prints only arrangements that add up to.
Exercise: Dice roll sum
CSE 143 Lecture 18 More Recursive Backtracking
CSC 172 DATA STRUCTURES.
Graphplan/ SATPlan Chapter
Exercise: Dice roll sum
Graphplan/ SATPlan Chapter
Local Search Algorithms
The "8 Queens" problem Consider the problem of trying to place 8 queens on a chess board such that no queen can attack another queen. What are the "choices"?
Backtracking, Search, Heuristics
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Local Search Algorithms
Backtracking, Search, Heuristics
Presentation transcript:

Analysis and design of algorithm Unit-6 BackTracking Analysis and design of algorithm

Outline Overview and mechanism Applications - 8-queen problem algorithm 8-queen problem algorithm analysis.

Overview Backtracking is a systematic method to iterate through all the possible configurations of a search space. It is a general algorithm/technique which must be customized for each individual application. Recursion is the key in backtracking programming. As the name sug­gests we back­track to find the solution.

Mechanism start with one possible move out of many available moves and try to solve the problem. If we are able to solve the problem with the selected move then we will print the solu­tion else we will back­track and select some other move and try to solve it. If none if the moves work out we will claim that there is no solution for the problem.

Model our solution as a vector a = (a1, a2, Model our solution as a vector a = (a1, a2, ..., an), where each element ai is selected from a finite ordered set Si . Such a vector might represent an arrangement where ai contains the ith element of the permutation. Or the vector might represent a given subset S, where ai is true if and only if the ith element of the universe is in S. At each step in the backtracking algorithm, we start from a given partial solution, say, a = (a1, a2, ..., ak), and try to extend it by adding another element at the end. After extending it, we must test whether what we have so far is a solution. If not, we must then check whether the partial solution is still potentially extendible to some complete solution. If so, recur and continue. If not, we delete the last element from a and try another possibility for that position, if one exists.

Applications It is basically used to solve the constraint satisfaction problems like N queen problem Sudoku Knight problem crossword

Algorithm general backtracking Pick a starting point. while(Problem is not solved) For each path from the starting point. check if selected path is safe, if yes select it and make recursive call to rest of the problem If recursive calls returns true, then return true. else undo the current move and return false. End For If none of the move works out, return false, NO SOLUTON.

8 queen problem by The 8 queen problem is a case of more general set of problems namely “n queen problem”.   The problem is : How to place n queen on n by n board, so that they don’t attack each other.

General Idea Q1 attacks some positions, therefore Q2 has to comply with these constraints and take place, not directly attacked by Q1. Placing Q3 is harder, since we have to satisfy constraints of Q1and Q2. Going the same way we may reach point, where the constraints make the placement of the next queen impossible. Therefore we need to relax the constraints and find new solution. To do this we are going backwards and finding new admissible solution. To keep everything in order we keep the simple rule: last placed, first displaced. In other words if we place successfully queen on the ith column but cannot find solution for (i+1)th queen, then going backwards we will try to find other admissible solution for the ith queen first. This process is called backtracking.

Algorithm for N queen Problem: 1) Start in the leftmost column 2) If all queens are placed return true 3) Try all rows in the current column. Do following for every tried row. a) If the queen can be placed safely in this row then mark this [row, column] as part of the solution and recursively check if placing queen here leads to a solution. b) If placing queen in [row, column] leads to a solution then return true. c) If placing queen doesn't lead to a solution then umark this [row, column] (Backtrack) and go to step (a) to try other rows. d) If all rows have been tried and nothing worked, return false to trigger backtracking.

Example: 4 queen problem.