Chris Pollett>
CS255 |
HW#1 --- last modified February 09 2022 23:21:33.Due date: Feb 14 Files to be submitted: Purpose: To gain experience with probabilistic analysis and our first randomized algorithms. Related Course Outcomes: LO1 -- Analyze or code a randomized algorithm. Specification: This homework will consist of two parts, a written part and a coding part. Both parts will be submitted in the Hw1.zip file. The written part should be in a file Hw1.pdf. For this part of the homework you should write solutions for the following questions. In what you turn in, first copy and paste the question, then write your solution to it beneath it.
For the coding part of the assignment, I want you to write a program CollectAllPermutations.java (if you use a language different than Java, check with me first that I know that language, and then modify the names of your programs appropriately and have a readme.txt explaining compilation and usage). This program will be compiled using Java 15 with the syntax: javac CollectAllPermutations.java Your program will then be run from the command using a command like: javac CollectAllPermutations n mode Here `n` is an integer and mode is either the word quiet or the word verbose. If mode is verbose It will use one of the two algorithms from class to generate a random permutation (your choice) on `n` values, and then print that the permutation as a space separated list of numbers, and then continue generating permutations until all the permutations of `n` values have been printed at least once. At which point it should output: "All permutations of `n` collected in `x` iterations" where `x` equal to the number of times it printed out a permutation. In quiet mode, the program operates in the same way, but does not write the permutations, instead only output the last line with the number of iterations required to generate all of them. For example, we might see (depending on the random number generator) an output like: java CollectAllPermutations 3 verbose 2 1 3 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 1 2 3 3 2 1 All permutations of 3 collected in 8 iterations If the mode had been quiet only the last line would be output. Include your code as part of the Hw1.zip file you submit. Then conduct 10 experiments for each positive integer between 2 and 11. I.e., Ten experiments for 2, ten for 3, etc (seed your random number generators differently each time). You can do this programmatically if you want. Determine the average number of iterations for each integer and its standard deviation. Plot the integers and the number of trials with the standard deviations on a clearly labeled graph where you fit the curve that you would expect based on the coupon collector problem to the data using `chi^2` minimization. How well does the curve fit? Write up your experiments and put the graphs in your Hw1.pdf file that you include in the Hw1.zip file you submit. Point Breakdown
|