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

  • Home
  • SEARCH
  • 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 7006665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:30:23+00:00 2026-05-27T21:30:23+00:00

Which is a more efficient. A Trie structure like this: struct TrieNode { char

  • 0

Which is a more efficient. A Trie structure like this:

struct TrieNode              
{
char letter;              
bool isWord;                
     TrieNode* subNodes[26]; 
};

or a Trie structure like this:

struct TrieNode
{ 
    char letter;
    bool isword;
    map<int, TrieNode*> subNodes;
};

Or is there just a better implementation altogether…
Also, could someone give me an explanation?

  • 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-27T21:30:24+00:00Added an answer on May 27, 2026 at 9:30 pm

    I would use the first, for simplicity and speed, but conceivably the second could save space.

    You don’t need the char letter element in either code.
    It’s redundant, because the way you look up a word is to take a letter of the key and use it either as an index into the subNode array, or a key into your map, so as to choose a subNode.
    Either way, you never need to look at letter.

    The way you know if the word is not in the trie is if you hit a null subnode, or if you exhaust your key without hitting a isWord subnode.

    BTW, if your trie doesn’t contain too many words, and if it does not change very often, you will always save about an order of magnitude of speed by transforming it into ad-hoc code.


    EDIT What I mean by ad-hoc code is that a trie is a kind of finite-state-machine, and a finite-state-machine is a kind of program. So you write a program to read the sorted dictionary, but instead of building a trie data structure, it writes out a program in your favorite language that looks like this:

    // XYZ is the prefix string that corresponds to a node in the trie
    bool XYZFunc(char* key){
        switch (*key){
        case '\0': return true /* if XYZ is a valid word, else false */; break;
        case 'a': return XYZaFunc(key+1); break;
        case 'b': return XYZbFunc(key+1); break;
        // etc. etc.
        }
    }
    

    This could be a lot of functions, but within reason the compiler should be able to handle it. Then to look up a word you just call the top-level function, and it returns true or false. At each node, the compiler will determine if it needs a jump table or not, so you don’t have to worry about that.

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

Sidebar

Related Questions

Which of these queries is more efficient, and would a modern DBMS (like SQL
Which is more efficient, "data.Length==0" or "data==string.Empty"? in this question there was an answer
This <cfif len(x)> Or <cfif x NEQ > Which one is more efficient and
I'm wondering which is more efficient. std::map< String, std::set<int> > or std::multimap< String, int
Which is more efficient for the compiler and the best practice for checking whether
Which is more efficient? SELECT theField FROM theTable GROUP BY theField or SELECT DISTINCT
which is more efficient (when managing over 100K records): A. Mysql SELECT * FROM
I am wondering which is more efficient, to store temporary data (related to that
In C# which is more memory efficient: Option #1 or Option #2? public void
Which Database table Schema is more efficient and why? Users (UserID, UserName, CompamyId) Companies

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.