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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:28:13+00:00 2026-05-12T08:28:13+00:00

I have a DAG. I have this operation to add a edge between two

  • 0

I have a DAG. I have this operation to add a edge between two nodes.

If A is reachable from B, then B is A’s parent. If A is reachable from B without going though another node, then B is A’s direct parent.

Requirements for this graph are:

  1. No cycles.
  2. For any node, there is a list of direct parents P[1],P[2],P[3]… P[i] is not a parent of P[j] for any i and j.

If adding a edge, requirement 1 is not met, the edge is not constructed.
If adding a edge, requirement 2 is not met, the edge is constructed, but the direct parents will be modified in a way such that requirement 2 is met.

For example, there are 3 nodes

  • A, direct parents: none
  • B, direct parents: A
  • C, direct parents: A

now, if I add a edge between B and C, we have

  • C, direct parents: A,B

but A is a parent of B, doesn’t meet requirement 2, thus A is removed from C’s direct parent, and we have

  • C, direct parents: B

Currently here is what I did:
Add edge from A to B (this A become B’s parent)

  1. Check if B is A’s parent by BFS. If so, do not add the edge.(this make sure there is no cycles)
  2. Check if A is already B’s parent by BFS. If so, do not add the edge.
  3. Find the intersection of A’s parent with B’s direct parent. This is done by find every parent of A though BFS. Remove the intersection from B’s direct parent, and add A as a direct parent of B.(2 and 3 make sure it meet requirement 2)

This is slow. It breaks down at 5k node level(I’m looking for this to handle any graph with less than 100k nodes), the speed become not acceptable, 0.02 second for adding a node edge.

I have a feeling step 1 and 2 can be done in 1 step with some other algorithm.

I thought of using topological ordering, but it have to transverse the entire graph, which is the worst case for my step 1&2. The ordering will be disrupted when the new node is added. so I have to run a topological ordering every time for a insert, so it doesn’t create any benefit.
For step 3, the entire set of A’s parents have to be found. The process is fairly slow, as on average it transverse a decent part of the graph.

How can I make this more efficient?

  • 1 1 Answer
  • 1 View
  • 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-12T08:28:14+00:00Added an answer on May 12, 2026 at 8:28 am

    Your question comes down to “Can inserting edges in a DAG be done faster than O(v+e)?” as per requirement (1). Requirement (2) is a more local constraint that doesn’t require checking the entire graph.

    I think the answer is no: you can’t do better than O(v+e) in the worst case (where v is the number of nodes/vertices and e is the number of edges).

    No doubt there are tricks to improve expected performance, depending on the properties of your DAG and how it changes over time. This appears to be an active research topic. For example, I imagine for some graphs it might be beneficial to cluster nodes. Inserting edges within a cluster then only requires checks within the cluster sub-DAG. But then you’d need a proper clustering strategy with support for cheaply updating the clustering when adding nodes, etc.

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

Sidebar

Related Questions

I have a large (100,000+ nodes) Directed Acyclic Graph (DAG) and would like to
have a php code like this,going to convert it in to C#. function isValid($n){
I have a DAG storing the relation between certain objects in my application. When
Suppose we have a DAG with one source. I would like to find nodes
I have a large directed, acylic graph (DAG) from which I would like to
I have to write an algorithm that find the path in DAG with single
have written this little class, which generates a UUID every time an object of
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have a session that looks like this: array(3) { [counter]=> int(0) [currentItem]=> string(1)
I got a question. i have tha following foreach loop: {foreach from=$films item=film key=id}

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.