Java Reference
In-Depth Information
Your recursive program should explore all possible placements of eight queens on the board and report all the
configurations in which no two queens are in jeopardy.
4. Write a recursive program to generate random sentences from a given BNF grammar. A BNF grammar is a
recursively defined file that defines rules for creating sentences from tokens of text. Rules can be recursively
self-similar. The following grammar can generate sentences such as “Fred honored the green wonderful child”:
<s>::=<np> <vp>
<np>::=<dp> <adjp> <n>|<pn>
<dp>::=the|a
<adjp>::=<adj>|<adj> <adjp>
<adj>::=big|fat|green|wonderful|faulty|subliminal|pretentious
<n>::=dog|cat|man|university|father|mother|child|television
<pn>::=John|Jane|Sally|Spot|Fred|Elmo
<vp>::=<tv> <np>|<iv>
<tv>::=hit|honored|kissed|helped
<iv>::=died|collapsed|laughed|wept
5. The Koch snowflake is a fractal that is created by starting with a line segment, then recursively altering it as follows:
1. Divide the line segment into three segments of equal length.
2. Draw an equilateral triangle that has the middle segment from step 1 as its base.
3. Remove the line segment that is the base of the triangle from step 2.
Figure 12.11 shows the first several iterations of the snowflake.
Figure 12.11
Koch snowflake
Write a program to draw the Koch snowflake on a DrawingPanel recursively.
 
Search WWH ::




Custom Search