-3

I'm implementing the following boggle algorithm:

I want to optimize it because it takes about 2 minutes and a half to find all words. Do you have any ideas on optimization techniques?

Guy Coder
  • 24,501
  • 8
  • 71
  • 136
Asdwq Qwksf
  • 141
  • 1
  • 2
  • 11
  • 2
    Is this your code? Or something you found? If you just found it, we need to see some effort before we'll really help. – Jon Egeland Dec 13 '11 at 03:03
  • 2
    You tagged your question with Java and C++ - which are you implementing it in? What ideas do you have about optimizing it? @Jon, the code is probably not his since it's 7.5 years old...unless he's just now getting around to it :) – Paul Dec 13 '11 at 03:05
  • Try using a stack approach rather than a recursive approach. Stacks are more efficient than recursion, especially in Java. – Ryan Amos Dec 13 '11 at 03:07
  • 1
    @Jon: The comments and copyrights on the page suggest that he *probably* didn't write this. – Mike Bailey Dec 13 '11 at 03:08

2 Answers2

0

You really want to have a look at this question (and answers) here: How to find list of possible words from a letter matrix [Boggle Solver]

There's solutions in Python, Perl, VB.NET and PHP. Most use Tries and optionally prefilter the dictionary using regexes.

Community
  • 1
  • 1
dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
0

I've written some Boggle-solving algorithms by creating letter trees which can be traversed to assemble and verify words. You save loads of space by using a tree-based structure in which words share similar letters, meaning you won't have to keep individual copies of each word.

If you didn't write the program on the website you provided, keep in mind that we won't do your work for you. You have to show us that you've spent considerable time on the problem instead of giving us a program and asking us to optimize it for you. A good first step would be to study the algorithm on the page and fully understand how it works. Or even better, try writing your own Boggle program from scratch to learn which techniques work best for you.

xikkub
  • 1,641
  • 1
  • 16
  • 28