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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:46:58+00:00 2026-05-27T10:46:58+00:00

Following is how my graph is defined. std::map< std::string, std::set<std::string> > g_db; and Following

  • 0

Following is how my graph is defined.

std::map< std::string, std::set<std::string> > g_db;

and Following is how I have written function to compute all the paths between two nodes, based on some of the previous question on this site.

void compute_all_paths(std::vector<std::string>& visited,  std::string& dest ) {  
    std::string back           = visited.back();    
    std::set<std::string> adj_stations = g_db.find(back)->second;

    for ( std::set<std::string>::iterator itr = adj_stations.begin();  itr != adj_stations.end(); ++itr )  {  
        if ( std::find(visited.begin(), visited.end(), *itr) != visited.end())
            continue;
        if (*itr == dest) {
            visited.push_back( *itr );    
            for ( std::vector<std::string>::size_type idx = 0; idx < visited.size(); idx++ ){  
                std::cout << visited[idx] << " ";  
            }
            std::cout << std::endl;  
            visited.erase( visited.begin() + (visited.size() - 1));    
            break;
        }
    }  
    for ( std::set<std::string>::iterator itr = adj_stations.begin();  itr != adj_stations.end();  itr++ )  {  
        if ( std::find(visited.begin(), visited.end(), *itr) != visited.end() || *itr == dest ) 
            continue;
        visited.push_back( *itr );    
        compute_all_paths(visited, dest );            
        visited.erase( visited.begin() + (visited.size() - 1));  
    }  
} 

My graph is very huge, this function is crashing with huge list of calls to recursive function with the following message:

Unhandled exception at 0x7c812afb in Railways.exe: Microsoft C++
exception: std::bad_alloc at memory location 0x00033748

For small graph this works very well but not for huge graph.

Can anybody help me to find the issue.

  • 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-27T10:46:58+00:00Added an answer on May 27, 2026 at 10:46 am

    Too many levels of recursivity can cause a stack overflow crash. That’s why recursivity is not well suited for large data sets.

    But all recursive calls can be reduced to loops. You should try removing recursive calls and replace them with loops.

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

Sidebar

Related Questions

I have the following graph: OrderLine OrderLineExtension OrderLineExtensionA OrderLineExtensionB OrderLineExtensionC OrderLine contains a Set
We have configured iReport to generate the following graph: The real data points are
I have a graph created with MS Chart like the following picture. As you
I've following data: I want to plot a graph shows for all x the
I have a graph defined as such: digraph G { rankdir=LR node[shape=circle] q_[shape=none label=]
I have the following code in my head jQuery(document).ready(function() { var pic = 0;
Let us say I have the following graph plotted using ggplot: Is there anyway
I have the following simple Graph class, where for each Node , I store
Consider the following graph: I'm trying to find a way to enumerate all possible
I've got the following deadlock graph that describes two sql statements that are deadlocking

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.