Original Post
I recently received this as an interview question. The interview is over and I did not get the job (so I'm not trying to cheat on an interview, just trying to further my knowledge of algorithms and data structures for the future).
The question is as follows:
[font="Times New Roman"]Write a function which will find all the words on ageneralized Boggle™ board. The functionshould take as input the board dimensions, the board, and a dictionary of validwords and it should output the list of all found words to the calling function. You should consider how your approach willperform with a large dictionary and a large board.
My solution to this was to perform a quicksort on the dictionary words. Then I would do a depth first search to get all of the permutations of letters along the board and use a binary search to see if the permutation is in the dictionary.
Based on the interview I guess this is not the best solution and at the time I could not think of a better one. Assuming the O(n log n) quicksort is a pre computational cost, each binary search is O(log n). The only thing I know of that could be faster than O(log n) would be to hash everything and have constant lookup time.
If anyone has some recommendations on better solutions to solving this problem I would love to hear them.
Thanks![/font]
[font="Times New Roman"][/font]
The question is as follows:
[font="Times New Roman"]Write a function which will find all the words on ageneralized Boggle™ board. The functionshould take as input the board dimensions, the board, and a dictionary of validwords and it should output the list of all found words to the calling function. You should consider how your approach willperform with a large dictionary and a large board.
My solution to this was to perform a quicksort on the dictionary words. Then I would do a depth first search to get all of the permutations of letters along the board and use a binary search to see if the permutation is in the dictionary.
Based on the interview I guess this is not the best solution and at the time I could not think of a better one. Assuming the O(n log n) quicksort is a pre computational cost, each binary search is O(log n). The only thing I know of that could be faster than O(log n) would be to hash everything and have constant lookup time.
If anyone has some recommendations on better solutions to solving this problem I would love to hear them.
Thanks![/font]
[font="Times New Roman"][/font]