Lecture17-3

# Lecture17-3 - DataStructures CSCI 132 Spring 2012 Lecture...

This preview shows pages 1–6. Sign up to view the full content.

1 Data Structures   CSCI 132, Spring 2012 Lecture 17 Backtracking

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 A Limerick int factorial(int sum) {if (sum == 1) return 1; if (sum != 1) return product(sum, factorial(sum - 1)); }
3 Backtracking It is often useful to solve a problem through trial and error , and backtracking: Try one step and carry it out as far as possible. If it doesn't lead to a solution, back up to an intermediate step and try another step. This is known as backtracking. If the steps in a solution to the problem are similar to the whole problem (i.e. they are smaller versions of the larger problem), then we can use recursion to implement this approach.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 The Eight Queens Problem Can we place 8 queens on a chessboard so that none can take another? (I.e. none share a row, column or diagonal)? Q
5 Strategy for solving the problem with n queens If we have m queens positioned on the board (n x n board), we need to find positions for the remaining n-m queens so that none attacks another. Given a configuration:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 03/09/2012.

### Page1 / 15

Lecture17-3 - DataStructures CSCI 132 Spring 2012 Lecture...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online