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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:37:32+00:00 2026-05-27T03:37:32+00:00

I have a directed acyclic graph I’m trying to implement but I’m not sure

  • 0

I have a directed acyclic graph I’m trying to implement but I’m not sure what structure I can use. I keep believing that a tree or adjacency list would be viable but I am not given nodes to work with.

So in this case I tried to implement it using a 2d array, storing the priorities, in degrees and out degrees. However, I’m having problems figuring out how to insert an edge between two vertices and how I can check if a vertice is another vertice’s parent in this way.

  • 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-27T03:37:33+00:00Added an answer on May 27, 2026 at 3:37 am

    When you say you’re “storing the priorities, in degrees and out degrees”, it suggests you don’t quite grok adjacency matrices. For an adjacency matrix M, vertices correspond to indices, and edges from v to u correspond to an entry in the matrix at Mvu (i.e. Mvu is the number of edges from v to u). The out-degree of a vertex v is ΣM*v; the in-degree is ΣMv*. If the matrix is in row-major order (Mrow, col), these correspond to the column and row sums, respectively.

    “Priority” isn’t a vertex property in plain DAGs. If you have priorities associated with the vertices, your graph class should contain another data structure mapping vertices to priorities (probably a vector, since vertices are usually numbered consecutively). Better still, have two graph classes: a DAG class, and a child PriorityDAG class that adds a priority property for nodes:

    class DAG {
    public:
        typedef int Vertex;
        ...
    };
    
    class PriorityDAG : public DAG {
    public:
        using DAG::Vertex;
        typedef int Priority;
    
        Priority priority(Vertex vertex);
    
    protected:
        std::vector<Priority> priorities;
        ...
    };
    

    If you’re ever going to have other types of graphs (undirected, cyclic), you can make a Graph class to be the parent of DAG.

    Thus, to insert an edge, increment the value Mvu. If v is a parent of u, then there is an edge from v to u, so Mvu > 0.

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

Sidebar

Related Questions

Let's say I have an acyclic directed graph such as a family tree (not
I have an XML file that encodes a directed acyclic graph (DAG) that represents
I have a directed cyclic graph. Some edges are FIXED and may not be
I have an acyclic directed graph. I would like to assign levels to each
I have a directed, positive weighted graph. Each edge have a cost of use.
I have Directed Graph in networkx. I want to only keep those nodes which
I have a directed acyclic graph(tree) described by (Parent1 -> Child1), (Parent2 -> Child2),
I have a large directed acyclic graph that I would like to visualize in
I have a large (100,000+ nodes) Directed Acyclic Graph (DAG) and would like to
Perhaps not directly programming related, but definitely product / commercially related. And I can't

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.