For each possible first letter for each possible

Info icon This preview shows pages 3–8. Sign up to view the full content.

View Full Document Right Arrow Icon
for (each possible first letter): for (each possible second letter): for (each possible third letter): ... print! This is called a depth-first search
Image of page 3

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

View Full Document Right Arrow Icon
4 Decision trees M A R T Y available chosen A R T Y M R T Y M A T Y M A R Y M A R T M A R T Y A T Y M R A R Y M T A R T M Y M R T Y A R Y M A T R T M A Y T M A R Y M A R Y T T M A Y R M A Y R T R M A Y T M A Y T R R T M Y A ... ... ... ... ... ...
Image of page 4
5 Backtracking backtracking : A general algorithm for finding solution(s) to a computational problem by trying partial solutions and then abandoning them ("backtracking") if they are not suitable. a "brute force" algorithmic technique (tries all paths; not clever) often (but not always) implemented recursively Applications: producing all permutations of a set of values parsing languages games: anagrams, crosswords, word jumbles, 8 queens combinatorics and logic programming
Image of page 5

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

View Full Document Right Arrow Icon
6 Backtracking algorithms A general pseudo-code algorithm for backtracking problems: explore( choices ): if there are no more choices to make: stop. – else: • Make a single choice C from the set of choices. – Remove C from the set of choices . • explore the remaining choices . • Un-make choice C . – Backtrack!
Image of page 6
7 Backtracking strategies • When solving a backtracking problem, ask these questions: What are the "choices" in this problem? • What is the "base case"? (How do I know when I'm out of choices?) How do I "make" a choice? • Do I need to create additional variables to remember my choices? • Do I need to modify the values of existing variables? How do I explore the rest of the choices? • Do I need to remove the made choice from the list of choices? Once I'm done exploring the rest, what should I do?
Image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern