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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:20:14+00:00 2026-06-06T01:20:14+00:00

Let E be a given directed edge set. Suppose it is known that the

  • 0

Let E be a given directed edge set. Suppose it is known that the edges in E can form a directed tree T with all the nodes (except the root node) has only 1 in-degree. The problem is how to efficiently traverse the edge set E, in order to find all the paths in T?

For example, Given a directed edge set E={(1,2),(1,5),(5,6),(1,4),(2,3)}. We know that such a set E can generate a directed tree T with only 1 in-degree (except the root node). Is there any fast method to traverse the edge set E, in order to find all the paths as follows:

Path1 = {(1,2),(2,3)}
Path2 = {(1,4)}
Path3 = {(1,5),(5,6)}

By the way, suppose the number of edges in E is |E|, is there complexity bound to find all the paths?

  • 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-06T01:20:15+00:00Added an answer on June 6, 2026 at 1:20 am

    I have not worked on this kind of problems earlier. So just tried out a simple solution. Check this out.

    public class PathFinder
    {
        private static Dictionary<string, Path> pathsDictionary = new Dictionary<string, Path>();
        private static List<Path> newPaths = new List<Path>();
        public static Dictionary<string, Path> GetBestPaths(List<Edge> edgesInTree)
        {
            foreach (var e in edgesInTree)
            {
                SetNewPathsToAdd(e);
                UpdatePaths();
            }
            return pathsDictionary;
        }        
        private static void SetNewPathsToAdd(Edge currentEdge) 
        {
            newPaths.Clear();
            newPaths.Add(new Path(new List<Edge> { currentEdge })); 
            if (!pathsDictionary.ContainsKey(currentEdge.PathKey()))
            {
                var pathKeys = pathsDictionary.Keys.Where(c => c.Split(",".ToCharArray())[1] == currentEdge.StartPoint.ToString()).ToList();
                pathKeys.ForEach(key => { var newPath = new Path(pathsDictionary[key].ConnectedEdges); newPath.ConnectedEdges.Add(currentEdge); newPaths.Add(newPath); });             
                pathKeys =  pathsDictionary.Keys.Where(c => c.Split(",".ToCharArray())[0] == currentEdge.EndPoint.ToString()).ToList();
                pathKeys.ForEach(key => { var newPath = new Path(pathsDictionary[key].ConnectedEdges); newPath.ConnectedEdges.Insert(0, currentEdge); newPaths.Add(newPath); });
            }            
        }
        private static void UpdatePaths()
        {
            Path oldPath = null;
            foreach (Path newPath in newPaths)
            {
                if (!pathsDictionary.ContainsKey(newPath.PathKey()))
                    pathsDictionary.Add(newPath.PathKey(), newPath);
                else
                {
                    oldPath = pathsDictionary[newPath.PathKey()];
                    if (newPath.PathWeights < oldPath.PathWeights)
                        pathsDictionary[newPath.PathKey()] = newPath;
                }
            }
        }        
    }
    
    public static class Extensions
    {
        public static bool IsNullOrEmpty(this IEnumerable<object> collection) { return collection == null || collection.Count() > 0; }
        public static string PathKey(this ILine line) { return string.Format("{0},{1}", line.StartPoint, line.EndPoint); }
    }
    public interface ILine 
    {
        int StartPoint { get; }
        int EndPoint { get; }
    }
    public class Edge :ILine 
    {
        public int StartPoint { get; set; }
        public int EndPoint { get; set; }
    
        public Edge(int startPoint, int endPoint)
        {
            this.EndPoint = endPoint;
            this.StartPoint = startPoint;
        }
    }
    public class Path :ILine
    {
        private List<Edge> connectedEdges = new List<Edge>();
        public Path(List<Edge> edges) { this.connectedEdges = edges; }
        public int StartPoint { get { return this.IsValid ? this.connectedEdges.First().StartPoint : 0; } }
        public int EndPoint { get { return this.IsValid ? this.connectedEdges.Last().EndPoint : 0; } }
        public bool IsValid { get { return this.EdgeCount > 0; } }
        public int EdgeCount { get { return this.connectedEdges.Count; } }
        // For now as no weights logics are defined
        public int PathWeights { get { return this.EdgeCount; } }
        public List<Edge> ConnectedEdges { get { return this.connectedEdges; } }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a function, let's say atoi, how can I find the header file I
Suppose that you have 10 stations that are sending packets at a given time
Given that I have the array Let Sum be 16 dintptr = { 0
Let's say I define a set of get and set functions for a given
Please let me know how can I find if it is Sunday on given
I have a directed graph with millions of vertices and edges. A set of
Let's say I have a string given by user in the following form: single,
Given a string, let's see rxrx , how can I convert the string into
Let's say I want to write a function that does the following: Given a
Let Os be a partially ordered set, and given any two objects O1 and

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.