CS 361: Algorithms and Data Structures |
|||
This assignment has both a written and a programming portion. Both are due at the beginning of class on the 14th. The written portion will be collected at the beginning of the class period as usual. The programming portion should be uploaded to Moodle by the beginning of the class period. For the programming, you can work by yourself or with a partner. I highly encourage you to work with a partner. If you do, be sure to put both of your names in the comment at the top of the Skiing.java file For the questions on the written portion of the homework that ask you to "design an algorithm", your answer should include the following:
|
|||
Written Questions
|
|||
Programming Question
Suppose a set of n people want to organize a ski trip. They go to a ski rental shop which has m pairs of skis (where m > n). We'll let h(i) denote the height of the ith person and s(j) denote the length of the jth pair of skis. We want to assign each skier a pair of skis that matches their height as closely as possible. In other words, we want to assign each skier a pair of skis such that the following difference in heights is minimized:
This question asks you to implement a dynamic programming algorithm that solves this problem. Your program should return the actual solution in the form of an array of length n where the ith entry is the ski assignment for person i. For example, suppose we had the following inputs: I have provided you with starter code for this question in the form of a Java file named Skiing.java. Inside, I have provided code for randomly generating arrays of human heights and ski lengths. I tried to generate realistic lengths so you'll notice both human and ski heights range between 61 inches (5 feet 1 inch) and 77 inches (6 feet 5 inches). You are free to add whatever static methods and variables you'd like however you should make sure that your final solution is implemented in the computeSolution() method. The input to this method will be an array of length n. The computeSolution() method should fill this array with the optimal assignment of skis to skiers. Just like we've done in class, it's a good idea to write one method that computes the value of the optimal solution and another method that uses this to compute the actual solution. |
|||
Submission Instructions Your Java code should be submitted in a zipped directory that contains your Skiing.java file. You and your partner only need to submit one directory. Please make sure that you put both of your names in the class comment for Skiing.java so I know who you worked with.Your code should compile with no errors and it should obey the specifications provided above. Please upload your zipped directory to Moodle by the beginning of class on Monday. |