23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

In Figure 3.26, we show a recursion trace of a call to PuzzleSolve(3,S,U),<br />

where S is empty <strong>and</strong> U = {a,b,c}. Dur<strong>in</strong>g the execution, all the permutations of the<br />

three characters are generated <strong>and</strong> tested. Note that the <strong>in</strong>itial call makes three<br />

recursive calls, each of which <strong>in</strong> turn makes two more. If we had executed<br />

PuzzleSolve(3,S, U) on a set U consist<strong>in</strong>g of four elements, the <strong>in</strong>itial call<br />

would have made four recursive calls, each of which would have a trace look<strong>in</strong>g<br />

like the one <strong>in</strong> Figure 3.26.<br />

Figure 3.26: Recursion trace for an execution of<br />

PuzzleSolve(3,S,U), where S is empty <strong>and</strong> U = {a, b,<br />

c}. This execution generates <strong>and</strong> tests all permutations<br />

of a, b, <strong>and</strong> c. We show the permutations generated<br />

directly below their respective boxes.<br />

204

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!