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 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
  • 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-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

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The best 'intuition' to have about the restrict keyword is… May 12, 2026 at 2:53 pm
  • Editorial Team
    Editorial Team added an answer OK all I did now is a bit dirty, but… May 12, 2026 at 2:53 pm
  • Editorial Team
    Editorial Team added an answer Your problem is this line in the server: if ((numbytes… May 12, 2026 at 2:53 pm

Related Questions

I have a DAG storing the relation between certain objects in my application. When
I'm elaborating over a problem which seems hard to me and I'm not expecting
I have a list of items (blue nodes below) which are categorized by the
I have a DAG representing a list of properties. These properties are such that

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.