CS 112 - Introduction to Computer Science II
Homework #4


Due: Monday 9/25 at the beginning of class

NOTE: This work is to be done in pairs.  This means that each team will perform one submission with all team names and studentIDs listed in the README file after the honor pledge.  Although team members can divide work, each team member should be able to informally present all work of his/her teammate.

1. Ordering Growth Rates: Written exercise R19.7.  Hint: Try very large values of n for comparison.

2. Removing Duplicates:  Copy all starter code before beginning.

a) Written exercise R19.10.  Clarification: To remove a[i], you would be moving all remaining elements a[i+1] ... a[last] down one place to a[i]...a[last-1].  That is, you would use a partially filled array (p. 308-309), removing duplicates as they are encountered.

b) Implement the algorithm of R19.10 using the style of Horstmann's selection sort and creating parallel testing files as appropriate.   In this case your performance measuring command will be "java RemoveDuplicateTimer".  Collect timing data as in section 19.2, using at least 6 values for n that take more than a millisecond and less than 5 minutes.  Does this data support your analysis of R19.10?

c) Written exercise R19.11. 

d) Implement and test the algorithm of R19.11 as in part (b), using DuplicateRemover2.java.  In this case your performance measuring command will be "java RemoveDuplicate2Timer".  Collect timing data as in section 19.2, using at least 6 values for n that take more than a millisecond and less than 5 minutes.  Does this data support your analysis of R19.11?

e) [10% Extra Credit] Devise a more efficient algorithm than in R19.11.  Do similar analysis and performance testing as before, with the command "java RemoveDuplicate3Timer".  Hint: Shifting elements repeatedly during removals is inefficient.  The use of a second array to hold non-duplicates is permitted.  This is an opportunity to practice time/space tradeoff in algorithm design.

3. Maze Escape: Programming exercise P18.14.  Call your file MazeEscaper.java.  Read the maze from standard input (without prompting), assuming all lines will be the same length.  I recommend reading each line as a String into an ArrayList<String>.  After reading all lines, use the ArrayList size and String length to dynamically create a 2D char array and initialize it with the String characters.  Find the starting position, and implement the algorithm described printing "true" or "false" as appropriate for full credit, or printing the path (including starting position) with "O"s for 10% extra credit.  (For simplicity, the extra credit output can leave searched maze positions marked with ".".)