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

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

View Full Document Right Arrow Icon
1 Data Structures   CSCI 132, Spring 2012 Lecture 17 Backtracking
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 A Limerick int factorial(int sum) {if (sum == 1) return 1; if (sum != 1) return product(sum, factorial(sum - 1)); }
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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:
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

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 Right Arrow Icon
Ask a homework question - tutors are online