I think your algorithm has some problems. First, all words have to start with the same letter, as you only call dfs with 0, 0 initially, the rest just after adding a character. Second, you only print out a word if you cannot do a move - but of course prefixes of such a string are words too. But the big issue has to do with combinatorial explosion. The number of possible words found this way grows exponentially in the size of the board. It's doable for a 4x4 board, the number of possible words will be less than 2^16, but it will grow rapidly when you increase the size. You should take your dictionary and preprocess it to get all possible prefixes of valid words. And while you create your words while walking the board, stop as soon as your constructed word so far is not a valid prefix. No point in continueing if the first two letters are "QX". ;-)

Abigail


In reply to Re: Depth First Search and Boggle by Abigail-II
in thread Depth First Search and Boggle by smgfc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.