|
6 | 6 | - R = Number of Rows
|
7 | 7 | - C = Number of Columns
|
8 | 8 |
|
9 | | -In order to figure out if a word exists in the list of words, it is require to do some sort of traversal on the board, generally DFS will do here. |
| 9 | +In order to figure out if a word exists in the board, it is required to do some sort of traversal on the board, generally DFS will do here. |
10 | 10 | Secondly, by using a trie, we can traverse the board and trie together one character at a time.
|
11 | 11 |
|
12 | 12 | Each DFS will be for the worst case, traversing the longest word in the word list.
|
13 | | -For example, a board full of a's and word list of different lengths of a's. The longest word could end up being as long as all the elements on the board. |
14 | | -So the run-time will total to O((R \* C)^2). |
| 13 | +For example, a board full of a's and word list of different lengths of a's. |
| 14 | +The longest word could end up being as long as all the elements on the board. |
| 15 | +So the run-time will total to O((R \* C)^2) but generally this will be lower for the average case with the use of the trie. |
15 | 16 |
|
16 | 17 | ```
|
17 | 18 | from collections import defaultdict
|
|
0 commit comments