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 8386049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:49:26+00:00 2026-06-09T17:49:26+00:00

The purpose: This function parses through a string trie following the path that matches

  • 0

The purpose: This function parses through a string trie following the path that matches an input string of characters. When all the char in the string are parsed, true is returned. I want to step over a char and return if there is still a valid path.

The application: the strings are a location hierarchy for a highway project. So, project 5 has an alignment C, that has an offset of N and a workzone 3; 5CN3. But, sometimes I want to define a string for all child locations for a project task that covers all the locations. So, ‘0’ is all locations; for a half day operation like grade dirt has no workzones – all the so to represent this task is all workzones in the north alignment C; 5CN0. same for if an operation covers the whole project; 5000.

Approaches: I could have used a wildcard ‘?’ function but I want to keep this specific step over for the purpose of abstracting the locations. Maybe ‘?’ is the right approach, but seems to loose some control. Also, this could be written without the for loop and use a position index parameter; maybe that is where this goes wrong – maybe on backtracking.

Code: nodeT is the trie nodes, word is the input string, this function is a bool and returns 1/0 if the string path exists.

bool Lexicon::containsWordHelper(nodeT *w, string word)) //check if prefix can be combined
{
    if(word == "") { //base case: all char found
        return true;
    } else {
        for(int i = 0; i < w->alpha.size(); i++) { //Loop through all of the children of the current node
            if (w->alpha[i].letter == word[0])
                return containsWordHelper(w->alpha[i].next, word.substr(1));
            else if (word[0] == '0') //if '0' then step over and continue searching for valid path
                containsWordHelper(w->alpha[i].next, word.substr(1)); //removed return here to allow looping through all the possible paths
        } //I think it is continuing through after the loop and triggering return false
    }
    return false; //if char is missing - meaning the exact code is not there
}

The problem is that this returns false when a ‘0’ wildcard is used. What is going wrong here? My knowledge is limited.

I hacked on this problem for awhile and used the ‘howboutthis howboutthat’ approach, and found that placing the return at the end of the step over statement works.

bool Lexicon::containsWordHelper(nodeT *w, string word, int &time, int &wag, string compare) //check if prefix can be combined
{
    if(word == "") { //base case: all letters found
        if ((w->begin-wag) <= time && time <= (w->end+wag)) 
            return w->isWord; // case 2: timecard check for high/low date range
        else if (time == ConvertDateToEpoch(9999, 01, 01)) return w->isWord; //this is for single code lookup w/o date
    } else {
        for(int i = 0; i < w->alpha.size(); i++) { //Loop through all of the children of the current node
            if (w->alpha[i].letter == word[0])
                return containsWordHelper(w->alpha[i].next, word.substr(1), time, wag, compare);
            else if (word[0] == 'ž')
                if (containsWordHelper(w->alpha[i].next, word.substr(1), time, wag, compare)) return true;
        }
    }
    return false; //if char is missing - meaning the exact code is not there
}

It seems logical that if I only one the path that ends in true to return then I should place the return after the recursion is done and then conditionally pass back only if true. It works and seems logical in retrospect, but my confidence in this is sketchy at best.

I still have the same question. What is/was going wrong?

  • 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-06-09T17:49:28+00:00Added an answer on June 9, 2026 at 5:49 pm

    Solved: place a return after an if statement containing the recursive call

    bool Lexicon::containsWordHelper(nodeT *w, string word) 
        {
            if(word == "") return w->isWord;
            else {
                for(int i = 0; i < w->alpha.size(); i++) {
                    if (w->alpha[i].letter == word[0])
                        return containsWordHelper(w->alpha[i].next, word.substr(1));
                    else if (word[0] == 'ž')
                        if (containsWordHelper(w->alpha[i].next, word.substr(1))) return true;
                }
            }
            return false;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that is calling wget via subprocess.Popen. The purpose of this
I have this function in my model the purpose of it is to get
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
Note that this function does not have a { and } body. Just a
[purpose] This simple command sequence runs expected in the Windows' CMD shell: dir &
What is the purpose this and why this be added when we add new
The purpose of this code is to pull upgrade.zip from a central server, extract
EDIT: Purpose of this Website: Its called Utopiapimp.com. It is a third party utility
My whole purpose of this is to get something looking like this: I want
What kind of tools or techniques exist for this purpose?

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.