19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

766 Chapter 20 Recursion<br />

FIGURE 20.17<br />

The program displays a solution <strong>to</strong> the Eight Queens problem.<br />

**20.35 (H-tree fractal) An H-tree (introduced at the beginning of this chapter) is a<br />

fractal defined as follows:<br />

1. Begin with a letter H. The three lines of the H are of the same length, as<br />

shown in Figure 20.1a.<br />

2. The letter H (in its sans-serif form, H) has four endpoints. Draw an H centered<br />

at each of the four endpoints <strong>to</strong> an H-tree of order 1, as shown in Figure<br />

20.1b. These Hs are half the size of the H that contains the four endpoints.<br />

3. Repeat Step 2 <strong>to</strong> create an H-tree of order 2, 3, . . . , and so on, as shown in<br />

Figure 20.1c–d.<br />

Write an applet that draws an H-tree, as shown in Figure 20.1.<br />

**20.36 (Hilbert curve) The Hilbert curve, first described by German mathematician<br />

David Hilbert in 1891, is a space-filling curve that visits every point in a square<br />

grid with a size of 2 * 2, 4 * 4, 8 * 8, 16 * 16, or any other power of 2.<br />

Write a <strong>Java</strong> applet that displays a Hilbert curve for the specified order, as<br />

shown in Figure 20.18.<br />

(a) (b) (c) (d)<br />

FIGURE 20.18<br />

A Hilbert curve with the specified order is drawn.<br />

20.37 (Sierpinski triangle) Write a program that prompts the user <strong>to</strong> enter the order<br />

and display the filled Sierpinski triangles as shown in Figure 20.19.<br />

**20.38 (Recursive tree) Write an applet <strong>to</strong> display a recursive tree as shown in<br />

Figure 20.20.

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

Saved successfully!

Ooh no, something went wrong!