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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:24:24+00:00 2026-05-13T22:24:24+00:00

I am trying to find a fast algorithm with modest space requirements to solve

  • 0

I am trying to find a fast algorithm with modest space requirements to solve the following problem.

For each vertex of a DAG find the sum of its in-degree and out-degree in the DAG’s transitive closure.

Given this DAG:

DAG from Wikipedia

I expect the following result:

Vertex #   Reacability Count  Reachable Vertices in closure
   7             5            (11, 8, 2, 9, 10)
   5             4            (11, 2, 9, 10)
   3             3            (8, 9, 10)
  11             5            (7, 5, 2, 9, 10)
   8             3            (7, 3, 9)
   2             3            (7, 5, 11)
   9             5            (7, 5, 11, 8, 3)
  10             4            (7, 5, 11, 3)

It seems to me that this should be possible without actually constructing the transitive closure. I haven’t been able to find anything on the net that exactly describes this problem. I’ve got some ideas about how to do this, but I wanted to see what the SO crowd could come up with.

  • 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-13T22:24:25+00:00Added an answer on May 13, 2026 at 10:24 pm

    I have constructed a viable solution to this question. I base my solution on a modification of the topological sorting algorithm. The algorithm below calculates only the in-degree in the transitive closure. The out-degree can be computed in the same fashion with edges reversed and the two counts for each vertex summed to determine the final “reachability count”.

    for each vertex V
       inCount[V] = inDegree(V)   // inDegree() is O(1)
       if inCount[V] == 0
          pending.addTail(V)
    
    while pending not empty
       process(pending.removeHead())
    
    function process(V)
       for each edge (V, V2)
          predecessors[V2].add(predecessors[V])   // probably O(|predecessors[V]|)
          predecessors[V2].add(V)
          inCount[V2] -= 1
          if inCount[V2] == 0
              pending.add(V2)
       count[V] = sizeof(predecessors[V])         // store final answer for V
       predecessors[V] = EMPTY                    // save some memory
    

    Assuming that the set operations are O(1), this algorithm runs in O(|V| + |E|). It is more likely, however, that the set union operation predecessors[V2].add(predecessors[V]) makes it somewhat worse. The additional steps required by the set unions depends on the shape of the DAG. I believe the worst case is O(|V|^2 + |E|). In my tests this algorithm has shown better performance than any other I have tried so far.

    Furthermore, by disposing of predecessor sets for fully processed vertices, this algorithm will typically use less memory than most alternatives. It is true, however, that the worst case memory consumption of the above algorithm matches that of constructing the transitive closure, but that will not be true for most DAGs.

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

Sidebar

Related Questions

I'm trying to find a more or less foolproof way to solve the following
I'm trying to come up with fast algorithm to find result of operation, where
Trying to find a good name for a method swapping each coordinate X and
I'm trying to find the best way to keep my clients updated as fast
Ok my problem isnt really a serious one, im just trying to find a
I'm trying to find an answer for a problem my developers are having. I
I'm trying to find a way to store my data with fast access (better
I'm trying to find some information explaining/showing how to integrate Microsoft Fast search with
I'm trying to find optimal (fast vs easiest) way to access SQL Server code
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]

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.