优化boggle算法
我正在实现以下 boggle 算法:
我想优化因为找到所有单词大约需要 2 分半钟。您对优化技术有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过创建字母树编写了一些解决难题的算法,可以遍历字母树来组装和验证单词。通过使用基于树的结构(其中单词共享相似的字母),您可以节省大量空间,这意味着您不必保留每个单词的单独副本。
如果您没有在您提供的网站上编写程序,请记住我们不会为您完成您的工作。您必须向我们表明您在问题上花费了大量时间,而不是给我们一个程序并要求我们为您优化它。好的第一步是研究页面上的算法并充分理解它是如何工作的。或者更好的是,尝试从头开始编写自己的 Boggle 程序,以了解哪些技术最适合您。
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.
你真的想在这里看看这个问题(和答案):如何从字母矩阵中查找可能的单词列表 [Boggle Solver]
有 Python、Perl、VB.NET 和 PHP 的解决方案。大多数使用 Trie 并可选择使用正则表达式对字典进行预过滤。
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.