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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:44:33+00:00 2026-06-15T21:44:33+00:00

I’m working on an algorithm to find all paths between two nodes in a

  • 0

I’m working on an algorithm to find all paths between two nodes in a graph. That’s it, I was able to encode all paths in an Array of Strings as follows:

String []paths = new String[50];

Note: I’m using an array of strings to store the paths, but I can store them in any other data structure when necessary.

Sample of the data in my array would be something like the table below, note that the letters are my data the hyphens used for visualization only:

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

All I need is to process the above array, and output all the combinations as:

ABC

AEC

DBC

DEC

I tried to solve this problem using the iterative approach “loops”, but I failed. I think we might to do this with recursion, but I’m not sure how to do that.
Also, I’m not aware if there is any data structure that deals with this problem. Something better to store the paths rather than an array of strings?

Anyway, here is what I’m working on with loops:

String []temp = new String[100];
for( r=0; r<paths.length ;r++ )
   for( c=0; c<paths[r].length() ;c++ )
      for( j=c+1; j<paths[r].length() ;j+1 )
         temp[r] += paths[j];
  • 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-15T21:44:34+00:00Added an answer on June 15, 2026 at 9:44 pm

    So the regular expression [AD][BE][C].

    That would be a better data structure too: a 90 degree turning of the arrays. That would eliminate checking the lengths (ABC versus DE).

    Nevertheless with your data structure:

    int maxPathLength = 3; // TODO calculate
    Set<String> results = new TreeSet<String>();
    process(paths, "", 0);
    
    public void process(String[] paths, String prefix, int i, Set<String> results) {
        if (i >= maxPathLength) {
            System.out.println(prefix);
            results.add(prefix);
            return;
        }
        for (String s : paths) {
             if (i < s.length()) {
                 process(paths, prefix + s.charAt(i), i + 1, results);
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.