© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

Polynomial Time Algorithms for the N-Queen Problem Rok sosic and Jun Gu.
Local Search Algorithms Chapter 4. Outline Hill-climbing search Simulated annealing search Local beam search Genetic algorithms Ant Colony Optimization.
8 Queens. Problem: Placing 8 queens on a chessboard such that they don’t attack each other Three different Prolog programs are suggessted as solutions.
PROLOG 8 QUEENS PROBLEM.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
B ACKTRACK SEARCH ALGORITHM. B ACKTRACKING Suppose you have to make a series of decisions, among various choices, where You don’t have enough information.
P Chapter 6 introduces the stack data type. p Several example applications of stacks are given in that chapter. p This presentation shows another use called.
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?
Search Problems Russell and Norvig: Chapter 3, Sections 3.1 – 3.3 Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm by Prof. Jean-Claude.
Chapter 15 Geography, Climate, and Natural Resources.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 2 Application Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2.
Chapter 6 (cont'd) Searching for Guinea Pig B: Case Study in Online Research.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Chapter 13 Income Inequality. Copyright © 2005 Pearson Addison-Wesley. All rights reserved
© 2006 Pearson Addison-Wesley. All rights reserved6-1 Chapter 6 Recursion as a Problem- Solving Technique.
© 2006 Pearson Addison-Wesley. All rights reserved6-1 More on Recursion.
Chapter 1 The Facts to Be Explained. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. Chapter 18 Conclusion: Where We Stand.
Chapter 1 Computer Networks and the Internet. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
Chapter 6 Wireless and Mobile Networks. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 3 Transport Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 3-2.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes.
Chapter 6 Human Capital. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 8 The Role of Technology in Growth. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2.
Chapter 5 Recursion as a Problem-Solving Technique.
Chapter 7 Multimedia Networking. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2.
Chapter 16 Resources and the Environment at the Global Level.
1 Applications of Recursion (Walls & Mirrors - Chapter 5)
/t/ / I d/ /d/ Try Again Go on /t/ / I d/ /d/
Data Structures Using C++ 2E Chapter 6 Recursion.
Chapter 1 The Art of Problem Solving © 2008 Pearson Addison-Wesley.
Data Structures Using C++ 2E Chapter 6 Recursion.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
COSC2007 Data Structures II
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Back Tracking Project Due August 11, 1999 N-queens: –A classic puzzle for chess buffs is the N- Queens problem. Simply stated: is it possible to place.
Chapter 12 Coping with the Limitations of Algorithm Power Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Two Dimensional Arrays
CSC 205 Programming II Lecture 18 The Eight Queens Problem.
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.
Please snarf the code for today’s class. Then think about the famous 8-Queen’s Puzzle. The question is: is there a way to arrange 8 queens on a (8x8) chessboard.
EXAMPLES OF RECURSION Towers of Hanoi Writing Linked Lists Backwards Recursive Insert 8 Queens Recognizing Simple Languages Prefix Expressions Conversion.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 5: Recursion as a Problem-Solving Technique Data Abstraction.
Two Dimensional Arrays. Two-dimensional Arrays Declaration: int matrix[4][11]; 4 x 11 rows columns
1 Data Structures CSCI 132, Spring 2014 Lecture 17 Backtracking.
Recursion as a Problem- Solving Technique Chapter 5 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Backtracking & Brute Force Optimization Intro2CS – weeks
An Analysis of the n- Queens problem Saleem Karamali.
 Chapter 7 introduces the stack data type.  Several example applications of stacks are given in that chapter.  This presentation shows another use called.
Chapter 5 Recursion as a Problem-Solving Technique
Intro to Computer Science II
Figure 5.1 a) Five queens that cannot attack each other, but that can attack all of column 6; b) backtracking to column 5 to try another square for the.
Sit-In Lab 1 Ob-CHESS-ion
Analysis and design of algorithm
Objective: Today we will investigate the ‘magic’ in magic squares.
Ch. 6 Recursion as a Problem Solving Technique
Applications of Matrices
Nonlinear Functions, Conic Sections, and Nonlinear Systems
CS Software Studio Assignment 1
Recursion as a Problem-Solving Technique
Introduction: Some Representative Problems
The N-Queens Problem Search The N-Queens Problem Most slides from Milos Hauskrecht.
Announcements Assignment #4 is due tonight. Last lab program is going to be assigned this Wednesday. ◦ A backtracking problem.
Presentation transcript:

© 2006 Pearson Addison-Wesley. All rights reserved 6-1 Chapter 6 Recursion as a Problem- Solving Technique

© 2006 Pearson Addison-Wesley. All rights reserved 6-2 Backtracking –A strategy for guessing at a solution and backing up when an impasse is reached Recursion and backtracking can be combined to solve problems

© 2006 Pearson Addison-Wesley. All rights reserved 6-3 The Eight Queens Problem Problem –Place eight queens on the chessboard so that no queen can attack any other queen Strategy: guess at a solution –There are 4,426,165,368 ways to arrange 8 queens on a chessboard of 64 squares

© 2006 Pearson Addison-Wesley. All rights reserved 6-4 The Eight Queens Problem An observation that eliminates many arrangements from consideration –No queen can reside in a row or a column that contains another queen Now: only 40,320 arrangements of queens to be checked for attacks along diagonals

© 2006 Pearson Addison-Wesley. All rights reserved 6-5 The Eight Queens Problem Providing organization for the guessing strategy –Place queens one column at a time –If you reach an impasse, backtrack to the previous column

© 2006 Pearson Addison-Wesley. All rights reserved 6-6 The Eight Queens Problem Figure 6-1 a) Five queens that cannot attack each other, but that can attack all of column 6; b) backtracking to column 5 to try another square for the queen; c) backtracking to column 4 to try another square for the queen and then considering column 5 again

© 2006 Pearson Addison-Wesley. All rights reserved 6-7 The Eight Queens Problem A recursive algorithm that places a queen in a column –Base case If there are no more columns to consider –You are finished –Recursive step If you successfully place a queen in the current column –Consider the next column If you cannot place a queen in the current column –You need to backtrack

© 2006 Pearson Addison-Wesley. All rights reserved 6-8 The Eight Queens Problem Figure 6-2 A solution to the Eight Queens problem