Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7180565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:22:33+00:00 2026-05-28T17:22:33+00:00

This is for a homework assignment, so I don’t want the exact code, but

  • 0

This is for a homework assignment, so I don’t want the exact code, but would appreciate any ideas that can help point me in the right direction.

The assignment is to write a boggle solving program. I’ve got the recursive part down I feel, but I need some insight on how to compare the current sequence of characters to the dictionary.

I’m required to store the dictionary in either a set or sorted list. I’ve been trying a way to implement this using a set. In order to make the program run faster and not follow dead end paths, I need to check and see if the current sequence of characters exists as a prefix to anything in the set (dictionary).

I’ve found that set.find() operation only returns true if the string is an exact match. In the lab requirements, the professor mentioned that:

“If the dictionary is stored in a Set, many data structure libraries provide a way to find the string in the Set that is closest to the one you are searching for. Such an operation could be used to quickly find a word with a given prefix.”

I’ve been searching today for a what the professor is describing. I’ve found a lot of information on tries, but since I’m required to use a list or set, I don’t think that will work.

I’ve also tried looking up algorithms for autocomplete functions, but the ones that I’ve found seem extremely complicated for what I’m trying to accomplish here.

I also was thinking of using strncmp() to compare the current sequence to a word from the dictionary set, but again, I don’t know how exactly that would function in this situation, if at all.

Is it worth it to continue investigating how this would work in a set or should I just try using a sorted list to store my dictionary?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:22:34+00:00Added an answer on May 28, 2026 at 5:22 pm

    As @Raymond Hettinger mentions in his answer, a trie would be extremely useful here. However, if you either are uncomfortable writing a trie or would prefer to use off-the-shelf components, you can use a cute property of how words are ordered alphabetically to check in O(log n) time whether a given prefix exists. The idea is as follows – suppose for example that you are checking for the prefix “thr.” If you’ll note, every word that begins with the prefix “thr” must be sandwiched between the strings “thr” and “ths.” For example, thr ≤ through < ths, and thr ≤ throat < ths. If you are storing your words in a giant sorted array, you can use a modified version of binary search to find the first word alphabetically at least the prefix of your choice and the first word alphabetically at least the next prefix (formed by taking the last letter of the prefix and incrementing it). If these are the same word, then nothing is between them and the prefix doesn’t exist. If they’re not, then something is between them and the prefix does it.

    Since you’re using C++, you can potentially do with a std::vector and the std::lower_bound algorithm. You could also throw all the words into a std::set and use the set‘s version of lower_bound. For example:

    std::set<std::string> dictionary;
    std::string prefix = /* ... */
    
    /* Get the next prefix. */
    std::string nextPrefix = prefix;
    nextPrefix[nextPrefix.length() - 1]++;
    
    /* Check whether there is something with the prefix. */
    if (dictionary.lower_bound(prefix) != dictionary.lower_bound(nextPrefix)) {
        /* ... something has that prefix ... */
    } else {
        /* ... no word has that prefix ... */
    }
    

    That said, the trie is probably a better structure here. If you’re interested, there is another data structure called a DAWG (Directed Acyclic Word Graph) that is similar to the trie but uses substantially less memory; in the Stanford introductory CS courses (where Boggle is an assignment), students actually are provided a DAWG containing all the words in the language. There is also another data structure called a ternary search tree that is somewhere in-between a binary search tree and a trie that may be useful here, if you’d like to look into it.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a homework assignment so I don't want to post any code, but
So first off, this is a homework assignment, so please don't write any code
Disclaimer: This is for a homework assignment, but the question is not regarding the
I know this sounds like a homework assignment, but it isn't. Lately I've been
Basically i am having problems with my code - this is homework so would
This is in relation to a homework assignment but this is not the homework
I was trying to solve this homework assignment but was unable to come up
I'm still not very good with data structures, but I have this homework assignment
This is part of a homework assignment. I've got several questions asking find the
I'm doing a basic homework assignment which looks like this: While input <> -1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.