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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:20:43+00:00 2026-05-30T14:20:43+00:00

Has the following problem got a name and is there an algorithm to solve

  • 0

Has the following problem got a name and is there an algorithm to solve it? :
Given a graph, either directed or not, find all the paths which satisfy the specification given by

  1. a list of exact nodes, or
  2. ‘*?’ which denotes just ‘any node or no node at all’, or
  3. ‘*{n}’ which denote ‘any n consecutively connected nodes’

e.g.

A -> B -> *? -> D which results in ABXD and ABYD and ABD etc.

or

A -> *{1} -> D -> *? -> E which results in ABXDZE and ABYDZE and ABDZE etc. etc.

thanks

p.s.
Does anyone know a graph library doing this either in R or perl or C?

  • 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-30T14:20:44+00:00Added an answer on May 30, 2026 at 2:20 pm

    What I did at the end was:

    1. The problem is to find all paths of length N between 2 nodes. Cycles are excluded.
    2. read the data in as an edgelist, e.g. pairs of from->to nodes (names of nodes are assumed to be unique)
    3. create a hashtable (or unordered_map in boost and stl, c++) of node names as keys and a hashtable as a value.
    4. this second hashtable will contain all nodes the first node leads to as keys.

    For example

    A->B
    A->C
    B->D
    C->E
    E->D
    

    the resultant data structure holding the input data in perl notation looks like this after reading in all the data as an ‘edgelist’:

    my %hash = (
    'A' => {'B' => 1, 'C' => 1},
    'B' => {'D' => 1},
    'C' => {'E' => 1},
    'E' => {'D' => 1},
    );
    

    finding if a pair of nodes is DIRECTLY connected can be done roughly as (perl):

    sub search {
        my ($from,$to) = @_;
        if( $to eq '*' ){ return defined($x=$hash{$from}) ? [keys $hash{$from}] : [] }
        return defined($x=$hash{$from}) && defined($x{$to}) ? [$to] : []
    }
    

    In the above function there is provision to return all the nodes a ‘from’ node is connected to, by setting $to to ‘*’. The return is an array ref of nodes connected directly to the $from parameter.

    Searching for the path between two nodes requires using the above function recursively.

    e.g.

    sub path {
        my ($from,$to, $hops, $save_results) = @_;
        if( $hops < 0 ){ return 0 }
        $results = search($from, '*');
        if( "".@$results == 0 ){ return 0 }
        $found = 0;
        foreach $result (@$results){
            $a_node = new Tree::Nary($result);
            if( path($result, $to, $hops-1, $a_node) == 1 ){
                $save_results->insert($save_results, -1, $a_node);
                $found = 1;
            }
        }
        return $found;
    

    }

    It’s ok to use recursion if the depth is not too much (i.e. $hops < 6 ?) because of stack overflow [sic].

    The most tricky part is to read through the results and extract the nodes for each path. After a lot of deliberation I decided to use a Tree::Nary (n-ary tree) to store the results. At the end we have the following tree:

         |-> B -> D
    A -> |-> C -> E -> D
    

    In order to extract all the paths, do:

    1. find all the leaf nodes
    2. start from each leaf node moving backwards via its parent to the root node and saving the node name.

    The above was implemented using perl, but have also done it in C++ using boost::unordered_map for hashtable. I haven’t yet added a tree structure in then C++ code.

    Results: for 3281415 edges and 18601 unique nodes, perl takes 3 mins to find A->’*’->’*’->B. I will give an update on the C++ code when ready.

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

Sidebar

Related Questions

I've got following problem: (c#) There is some class (IRC bot), which has method,
I have got the following problem since the server has safe mode turned on,
I've got a problem and hope you can help me find a solution. Name
Has anyone encountered the following problem: I have IIS7 running on my computer. On
i am looking for opinions if the following problem maybe has a better/different/common solution:
I have list in python which has following entries name-1 name-2 name-3 name-4 name-1
My problem is quite simple. I want the following macro #define PROXYPASS(name, param) \
I've got this problem and I can't for the life of me find a
I've got the following problem. My table ( geo_table ) structure is as follows:
I've got the following problem: I'm using the PHP XML DOM parser and when

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.