14-Recursive-Backtracking

14-Recursive-Backtracking - CS106X Handout 14 Autumn 2009...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: CS106X Handout 14 Autumn 2009 October 9 th , 2009 Recursive Backtracking Recursive Backtracking So far, all of the recursive algorithms we have seen have shared one very important property: each time a problem was recursively decomposed into a simpler instance of the same problem, only one such decomposition was possible; consequently, the algorithm was guaranteed to produce a solution to the original problem. Today we will begin to examine problems with several possible decompositions from one instance of the problem to another. That is, each time we make a recursive call, we will have to make a choice as to which decomposition to use. If we choose the wrong one, we will eventually run into a dead end and find ourselves in a state from which we are unable to solve the problem immediately and unable to decompose the problem any further; when this happens, we will have to backtrack to a "choice point" and try another alternative. You’ll want to read Chapter 7 of the reader very carefully. We’ll complement the reader with a good number of additional examples not in the reader. If we ever solve the problem, great: we’re done. Otherwise, we need to keep exploring all possible paths by making choices and, when they prove to have been wrong, backtracking to the most recent choice point. What’s really interesting about backtracking is that we only back up in the recursion as far as we need to go to reach a previously unexplored choice point. Eventually, more and more of these choice points will have been explored, and we will backtrack further and further. If we happen to backtrack to our initial position and find ourselves with no more choices from that initial position, the particular problem at hand is unsolvable. Finish up Chapters 5 and 6, and start reading Chapter 7. Your Boggle assignment assumes you’re familiar with all of the material in Chapters 5 – 7, so make sure you read through it before tackling it. 2 Shrinking A Word [courtesy of Julie Zelenski] Consider the simply stated question: Is it possible to take an English word and remove all of its letters in some order such that every string along the way is also an English word? Sometimes it’s possible. For example, we can shrink the word "smart" down to the empty string while obeying the restriction that all of the intervening strings are also legitimate words. Check this out: "smart" "mart" "art" "at" "a" "" We elect to first remove the s , then the m , then the r , then the t , and finally the a . Note that every single string in the above diagram is an English word. That means that, for the purposes of the this problem, it’s possible to shrink the word " smart " down to the empty string....
View Full Document

This note was uploaded on 03/07/2010 for the course CS 201 taught by Professor Selimaksoy during the Spring '09 term at Bilkent University.

Page1 / 14

14-Recursive-Backtracking - CS106X Handout 14 Autumn 2009...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online