Übungsblatt 06b

Recursion
PI-1 2008/09
 

 

Assignment 1. Recursive Tree  UE,PR (15 points)

Write a Java program Tree.java that takes a command-line argument N and produces the following recursive pattern for N equal to 1,2,3,4,5, and 8.

N=1N=2N=3
N=4N=5N=8

 

Suggestion. As an creative addition, you may introduce some random variations (angle, size) when drawing each sub-tree.

Add (at least) the following comments according to Javadoc:

Submit Tree.java to Goya!



Assignment 2. Permutations 
UE

Write a program Permutations.java that takes a command-line argument N and prints out all N! permutations of the first N letters of the alphabet (you can assume that N is no greater than 26). A permutation of N elements is one of the N! possible orderings of the N elements. For example, for N=3 your program should produce the following 3!=6 permutations as output (don't worry about the order in which the 6 permutations are generated):

        % java Permutations 3
        bca cba cab acb bac abc


 

Assignment 3. Recursive Squares UE,PR (10 points)

Write a program Square.java that takes a command-line argument N in the range 1..4 and that produces one of the the following recursive graphical patterns. Note: The ratio of the sizes of the squares is 2.2:1. To draw a shaded square draw a filled gray square, then draw an unfilled black square.

N=1N=2N=3N=4

Add (at least) the following comments according to Javadoc:

Submit Square.java to Goya!