Insert all words from a large file (such as the novel “War and Peace”, which is available on the Internet) into a hash set and a tree set. Time the results. Which data structure is faster?

Complete the following file:

CompareHashAndTree.java

/** A program to read in a large file into both a hash set and a tree set and time the results to see which data structure is faster. A good Internet source is http://www.gutenberg.org/wiki/Main_Page */ ... public class CompareHashAndTree { public static void main(String[] args) throws FileNotFoundException { String filename = "war-and-peace.txt"; // Use stop watch to time hash set insertions StopWatch timer = new StopWatch(); // If you were to read the file twice, the second time would // be faster because the file contents would be cached // To fairly measure the cost of inserting into each set type, // first read the words from file and insert into array list Scanner in = new Scanner(new File(filename)); in.useDelimiter("[^A-Za-z']"); . . . in.close(); // Now insert the words from the array list into a hash set timer.start(); ... timer.stop(); System.out.println("Elapsed time for hash set: " + timer.getElapsedTime() + " milliseconds"); timer.reset(); // Now insert the words from the array list into a tree set timer.start(); ... timer.stop(); System.out.println("Elapsed time for tree set: " + timer.getElapsedTime() + " milliseconds"); } }