17-recursive_backtracking

17-recursive_backtracking - CSE143 Lecture17...

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

View Full Document Right Arrow Icon
CSE 143 Lecture 17 Recursive Backtracking   slides created by Marty Stepp http://www.cs.washington.edu/143/ ideas and examples taken from Stanford University CS slides/lectures
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 Exercise: Permutations Write a method  permute  that accepts a string as a parameter  and outputs all possible rearrangements of the letters in that  string.  The arrangements may be output in any order. Example: permute("MARTY") outputs the following sequence of lines: MARTY MARYT MATRY MATYR MAYRT MAYTR MRATY MRAYT MRTAY MRTYA MRYAT MRYTA MTARY MTAYR MTRAY MTRYA MTYAR MTYRA MYART MYATR MYRAT MYRTA MYTAR MYTRA AMRTY AMRYT AMTRY AMTYR AMYRT AMYTR ARMTY ARMYT ARTMY ARTYM ARYMT ARYTM ATMRY ATMYR ATRMY ATRYM ATYMR ATYRM AYMRT AYMTR AYRMT AYRTM AYTMR AYTRM RMATY RMAYT RMTAY RMTYA RMYAT RMYTA RAMTY RAMYT RATMY RATYM RAYMT RAYTM RTMAY RTMYA RTAMY RTAYM RTYMA RTYAM RYMAT RYMTA RYAMT RYATM RYTMA RYTAM TMARY TMAYR TMRAY TMRYA TMYAR TMYRA TAMRY TAMYR TARMY TARYM TAYMR TAYRM TRMAY TRMYA TRAMY TRAYM TRYMA TRYAM TYMAR TYMRA TYAMR TYARM TYRMA TYRAM YMART YMATR YMRAT YMRTA YMTAR YMTRA YAMRT YAMTR YARMT YARTM YATMR YATRM YRMAT YRMTA YRAMT YRATM YRTMA YRTAM YTMAR YTMRA YTAMR YTARM YTRMA YTRAM
Background image of page 2
3 Examining the problem Think of each permutation as a set of choices or  decisions : Which character do I want to place first? Which character do I want to place second? ... solution space : set of all possible sets of decisions to explore We want to generate all possible sequences of decisions. for (each possible first letter): for (each possible second letter): for (each possible third letter): ...
Background image of page 3

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

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

This note was uploaded on 01/04/2011 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Page1 / 13

17-recursive_backtracking - CSE143 Lecture17...

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

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