|
| 1 | +# Assignment Note |
| 2 | + |
| 3 | +>Write a program to play the word game Boggle®. |
| 4 | +> |
| 5 | +> [The Boggle game](https://coursera.cs.princeton.edu/algs4/assignments/boggle/specification.php). Boggle is a word game designed by Allan Turoff and distributed by Hasbro. It involves a board made up of 16 cubic dice, where each die has a letter printed on each of its 6 sides. At the beginning of the game, the 16 dice are shaken and randomly distributed into a 4-by-4 tray, with only the top sides of the dice visible. The players compete to accumulate points by building valid words from the dice, according to these rules: |
| 6 | +> - A valid word must be composed by following a sequence of adjacent dice—two dice are adjacent if they are horizontal, vertical, or diagonal neighbors. |
| 7 | +> - A valid word can use each die at most once. |
| 8 | +> - A valid word must contain at least 3 letters. |
| 9 | +> - A valid word must be in the dictionary (which typically does not contain proper nouns). |
| 10 | +
|
| 11 | +see also: [Nifty Boggle](https://www-cs-faculty.stanford.edu/~zelenski/boggle/) |
| 12 | + |
| 13 | +``` |
| 14 | +ASSESSMENT SUMMARY |
| 15 | +
|
| 16 | +Compilation: PASSED |
| 17 | +API: PASSED |
| 18 | +
|
| 19 | +SpotBugs: PASSED |
| 20 | +PMD: PASSED |
| 21 | +Checkstyle: PASSED |
| 22 | +
|
| 23 | +Correctness: 13/13 tests passed |
| 24 | +Memory: 3/3 tests passed |
| 25 | +Timing: 9/9 tests passed |
| 26 | +
|
| 27 | +Aggregate score: 100.00% |
| 28 | +[ Compilation: 5%, API: 5%, Style: 0%, Correctness: 60%, Timing: 10%, Memory: 20% ] |
| 29 | +``` |
| 30 | + |
| 31 | +From FAQ: [Possible Optimizations](https://coursera.cs.princeton.edu/algs4/assignments/boggle/faq.php) |
| 32 | + |
| 33 | +> You will likely need to optimize some aspects of your program to pass all of the performance points (which are, intentionally, more challenging on this assignment). Here are a few ideas: |
| 34 | +> |
| 35 | +> - Make sure that you have implemented the critical backtracking optimization described above. This is, by far, the most important step—several orders of magnitude! |
| 36 | +> - Think about whether you can implement the dictionary in a more efficient manner. Recall that the alphabet consists of only the 26 letters A through Z. |
| 37 | +> - Exploit that fact that when you perform a prefix query operation, it is usually almost identical to the previous prefix query, except that it is one letter longer. |
| 38 | +> - Consider a nonrecursive implementation of the prefix query operation. |
| 39 | +> - Precompute the Boggle graph, i.e., the set of cubes adjacent to each cube. But don't necessarily use a heavyweight Graph object. |
| 40 | +
|
| 41 | + |
| 42 | +**Key points**: |
| 43 | +- DFS |
| 44 | +- Trie (26-way vs. TST) |
| 45 | +- Prefix search (Recursive vs. Non-recursive) |
| 46 | +- Reuse Trie search node to reduce duplicate search cost |
| 47 | + |
| 48 | +With Modified TST and non-recursive prefix search, I still only get 98/100. May be recursive dfs can be optimized, will find out later. |
| 49 | + |
| 50 | +``` |
| 51 | +Test 2: timing getAllValidWords() for 5.0 seconds using dictionary-yawl.txt |
| 52 | + (must be <= 2x reference solution) |
| 53 | + - reference solution calls per second: 8541.72 |
| 54 | + - student solution calls per second: 4007.69 |
| 55 | + - reference / student ratio: 2.13 |
| 56 | +
|
| 57 | +=> passed student <= 10000x reference |
| 58 | +=> passed student <= 25x reference |
| 59 | +=> passed student <= 10x reference |
| 60 | +=> passed student <= 5x reference |
| 61 | +=> FAILED student <= 2x reference |
| 62 | +
|
| 63 | +Total: 8/9 tests passed! |
| 64 | +``` |
| 65 | + |
| 66 | +With 26-way Trie, easily got 100/100. |
| 67 | + |
| 68 | +Note: when using 26-way Trie, one should transform index of letters to be in the range of R, and remember to convert them back to letters when iterating all keys of Trie, otherwise your words would be *eaten*, lol. |
| 69 | + |
| 70 | +``` |
| 71 | +Test 2: timing getAllValidWords() for 5.0 seconds using dictionary-yawl.txt |
| 72 | + (must be <= 2x reference solution) |
| 73 | + - reference solution calls per second: 8085.84 |
| 74 | + - student solution calls per second: 4446.44 |
| 75 | + - reference / student ratio: 1.82 |
| 76 | +
|
| 77 | +=> passed student <= 10000x reference |
| 78 | +=> passed student <= 25x reference |
| 79 | +=> passed student <= 10x reference |
| 80 | +=> passed student <= 5x reference |
| 81 | +=> passed student <= 2x reference |
| 82 | +
|
| 83 | +Total: 9/9 tests passed! |
| 84 | +``` |
0 commit comments