An of a collection of letters is a word that is a rearrangement of all the letters in that collection. For example, anagrams of idte are diet, edit, and tide. An anagram of importunate is permutation. An anagram of excitation is intoxicate. Here is the interface for a class that stores words and lets you find anagrams: As you would expect, the constructor creates an empty dictionary, and the function adds a word (stripped of any non-letters) to the dictionary. The function takes a string and a function, and for every word in the dictionary that is an anagram of the letters in the string, it calls the callback function with that word as an argument. For example, We have written . Your assignment is to write a more efficient correct implementation. If you wish, you can do this by starting with our implementation in (the only source file you will modify and turn in), and changing the data structures and algorithms that implement the class and its member functions. You are free to add, change, or even delete classes or functions in if you want to. Correctness will count for 40% of your score, although if you turn in a correct implementation that is no faster than the horridly inefficient one we gave you, you will get zero correctness points (since you could just as well have turned in that same horridly inefficient program). Of course, we have to give you some assumptions about the way clients will use Dictionary so that you know what needs to be faster. The client may call tens of thousands of times. The collection of letters for which we want to find all the anagrams is typically about four to ten letters, but may well be more than that. Your program should be able to process tens of thousands of requests for anagrams quickly. Performance will count for 50% of your score (and your report for the remaining 10%). To earn any performance points, your program must be correct. (Who cares how fast a program is if it produces incorrect results?) This is a critical requirement you be certain your program produces the correct results and does not do anything undefined. Given that you are starting from a correct program, this should be easier than if you had to start from scratch. The faster your program performs on the tests we make, the better your performance score. When we do the performance tests on your program, we will create a dictionary, insert a bunch of words, start the clock, do a lot of lookups, stop the clock, and destroy the dictionary. This means that your insertions don�
�t have to be fast (within reason) as they build the data structures required for efficient lookups. To give you a taste of how fast the program can be, we did this project and produced , , and . Put the executable file in the same directory as the file we supply in , and try the program on with an collection of letters like intoxicate or Veronica Snot. When you believe your implementation is correct, and youre ready to test its correctness and speed, transfer it to the SEASnet Linux server. On that server, run this command: It will deposit several files in the current directory, then build and run correctness tests and a performance test. If your implementation does not pass the correctness tests, it will earn performance points. Our solution passes the basic and thorough correctness tests and runs in about 10 milliseconds. While the exact performance scoring has not yet been determined, we expect something approximately like the following: times below 20 ms would earn the full 50 performance points; below 50 ms, 45 points; below 100 ms, 40 points; below 200 ms, 35 points; below 400 ms, 30 points; below 8000 ms, 25 points. For implementations that take longer than about 8 seconds, we will have to run a limited performance test, for which its hard to say in advance what the scoring will be. Here are some requirements your program must meet: By Wednesday, June 3, there will be a link on the class webpage that will enable you to turn in your source files and report. You will turn in a zip file containing two files: Your report will count for 10% of your score. Well be reading it with this in mind: If you were standing around a whiteboard talking about your design and gave this description, would a CS grad student know enough about what you had in mind to be able to code it up without asking you any further questions? By default under Visual C++, when you build an executable file, it builds it in the Debug configuration. This is nice when youre not yet sure your program is correct, because the compiler inserts extra code to support giving you extra information if your program crashes. This extra code takes time to execute, however. When you are sure your program is correct, and youd like to see how fast it can run, youll want to build your program in the Release configuration. To do this in Visual C++: Under Xcode, select Product / Build For / Profiling to turn on optimization. Under Linux, the to the command turns on optimization; for example, to produce an optimized executable named :