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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:59:39+00:00 2026-06-08T21:59:39+00:00

I have a recursive function that parses a trie string database replacing with all

  • 0

I have a recursive function that parses a trie string database replacing with all the characters in each node. On the recursive call an edit count is incremented and then the new string is tested for 1) if all nodes have been parsed and 2) if the string equals a string on a list of approved strings. So, the result should be the edit distance between the test string and all the possible strings in the database.

void suggestCorrections(nodeT *w, Set<CorrectionT> &suggest, int index, string test, string final, double edits)
{   
    if (word == "") {
        if (containsCode(final)) //compare with list of approved strings
            updateSet(w, suggest, final, edits);

    } else  { //continue to search path
        if( w->alpha.size() > index) {
            if (test[0] == w->alpha[index].char)
                suggestCorrections(w->alpha[index].next, suggest, 0, test.substr(1), final+test[0], edits); //follow matching char 
            suggestCorrections(w, suggest, ++index, test, final, edits);//check next path
            suggestCorrections(w->alpha[index].next, suggest, 0, test.substr(1), final+w->alpha[index].char, ++edits);//follow path
        }
    }
}

struct CorrectionT {
    double editDistance; //stackItems
    string suggestedWord; //stackItems
    string suggestDescription;
    string gates;
};

The problem is when the w->alpha.size() is equal to index – the path is correctly ended but then the last path suggestCorrections(w->alpha[index].next, suggest, 0, test.substr(1), final+w->alpha[index].char, ++edits); is entered, when index is incremented past the end of w->alpha. Why does the happen? And how is it fixed?

I think it is backtracking back through the function when the end of the path is met. I don’t want it to backtrack. I checked the call stack and setup breaks throughout but this seems like a conceptual issue not a bug. I also read a textbook chapter on recursion and the Wikipedia page – I understand the concept of backtracking, but not the implementation (or desired lack of) in this specific case. I used backtracking to build the trie database and it worked there, but that is different enough from here that I cannot figure this out.

  • 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-08T21:59:42+00:00Added an answer on June 8, 2026 at 9:59 pm

    In the second-to-last call to suggestCorrections, you’re passing ++index. That is incrementing the value of index, which is then passed in on the last call to suggestCorrections. I haven’t really tried to understand your code, but it looks like you probably just want to pass index+1 in the second-to-last call, rather than ++index.

    In general, hiding increment operations inside function call arguments isn’t good coding practice (in my opinion, at least). It makes it hard to read and debug the code.

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

Sidebar

Related Questions

I have a recursion function that parses an object/array with a global variable. If
Lets say I have a recursive function that creates lists within lists. It return
I have a simple recursive function RCompare() that calls a more complex function Compare()
Is it possible to have a PHP function that is both recursive and anonymous?
I have a function that builds substrings given a string recursively. Could anyone please
I have a recursive function which does a sort of tree process where each
So I have built a recursive function that generates a collection of Category objects.
I am creating a recursive js function which basically parses a string. I do
Say I have a recursive function that I want to know how many times
I have a simple recursive function that calculates a simple pendulum swing decay, using

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.