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

The Archive Base Latest Questions

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

I am trying to determine the best time efficient algorithm to accomplish the task

  • 0

I am trying to determine the best time efficient algorithm to accomplish the task described below.

I have a set of records. For this set of records I have connection data which indicates how pairs of records from this set connect to one another. This basically represents an undirected graph, with the records being the vertices and the connection data the edges.

All of the records in the set have connection information (i.e. no orphan records are present; each record in the set connects to one or more other records in the set).

I want to choose any two records from the set and be able to show all simple paths between the chosen records. By ‘simple paths’ I mean the paths which do not have repeated records in the path (i.e. finite paths only).

Note: The two chosen records will always be different (i.e. start and end vertex will never be the same; no cycles).

For example:

     If I have the following records:         A, B, C, D, E      and the following represents the connections:          (A,B),(A,C),(B,A),(B,D),(B,E),(B,F),(C,A),(C,E),         (C,F),(D,B),(E,C),(E,F),(F,B),(F,C),(F,E)          [where (A,B) means record A connects to record B] 

If I chose B as my starting record and E as my ending record, I would want to find all simple paths through the record connections that would connect record B to record E.

    All paths connecting B to E:       B->E       B->F->E       B->F->C->E       B->A->C->E       B->A->C->F->E 

This is an example, in practice I may have sets containing hundreds of thousands of records.

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

    It appears that this can be accomplished with a depth-first search of the graph. The depth-first search will find all non-cyclical paths between two nodes. This algorithm should be very fast and scale to large graphs (The graph data structure is sparse so it only uses as much memory as it needs to).

    I noticed that the graph you specified above has only one edge that is directional (B,E). Was this a typo or is it really a directed graph? This solution works regardless. Sorry I was unable to do it in C, I’m a bit weak in that area. I expect that you will be able to translate this Java code without too much trouble though.

    Graph.java:

    import java.util.HashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.Map; import java.util.Set;  public class Graph {     private Map<String, LinkedHashSet<String>> map = new HashMap();      public void addEdge(String node1, String node2) {         LinkedHashSet<String> adjacent = map.get(node1);         if(adjacent==null) {             adjacent = new LinkedHashSet();             map.put(node1, adjacent);         }         adjacent.add(node2);     }      public void addTwoWayVertex(String node1, String node2) {         addEdge(node1, node2);         addEdge(node2, node1);     }      public boolean isConnected(String node1, String node2) {         Set adjacent = map.get(node1);         if(adjacent==null) {             return false;         }         return adjacent.contains(node2);     }      public LinkedList<String> adjacentNodes(String last) {         LinkedHashSet<String> adjacent = map.get(last);         if(adjacent==null) {             return new LinkedList();         }         return new LinkedList<String>(adjacent);     } } 

    Search.java:

    import java.util.LinkedList;  public class Search {      private static final String START = 'B';     private static final String END = 'E';      public static void main(String[] args) {         // this graph is directional         Graph graph = new Graph();         graph.addEdge('A', 'B');         graph.addEdge('A', 'C');         graph.addEdge('B', 'A');         graph.addEdge('B', 'D');         graph.addEdge('B', 'E'); // this is the only one-way connection         graph.addEdge('B', 'F');         graph.addEdge('C', 'A');         graph.addEdge('C', 'E');         graph.addEdge('C', 'F');         graph.addEdge('D', 'B');         graph.addEdge('E', 'C');         graph.addEdge('E', 'F');         graph.addEdge('F', 'B');         graph.addEdge('F', 'C');         graph.addEdge('F', 'E');         LinkedList<String> visited = new LinkedList();         visited.add(START);         new Search().depthFirst(graph, visited);     }      private void depthFirst(Graph graph, LinkedList<String> visited) {         LinkedList<String> nodes = graph.adjacentNodes(visited.getLast());         // examine adjacent nodes         for (String node : nodes) {             if (visited.contains(node)) {                 continue;             }             if (node.equals(END)) {                 visited.add(node);                 printPath(visited);                 visited.removeLast();                 break;             }         }         for (String node : nodes) {             if (visited.contains(node) || node.equals(END)) {                 continue;             }             visited.addLast(node);             depthFirst(graph, visited);             visited.removeLast();         }     }      private void printPath(LinkedList<String> visited) {         for (String node : visited) {             System.out.print(node);             System.out.print(' ');         }         System.out.println();     } } 

    Program Output:

    B E  B A C E  B A C F E  B F E  B F C E  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Lookup the technique called web scraping. Basically, you have to… May 11, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer You have to define a computational model, give an estimation… May 11, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer Okay, the solution was to export the file from excel… May 11, 2026 at 7:04 pm

Related Questions

I am using LINQ and am having a hard time understanding how I can
I am trying to store a large amount of boolean information that is determined
I have encountered a strange Invalid Packet Lenght (that is how the error is
I am trying to determine the best directory structure of my application i have:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.