I want to represent a DAG as JSON text and wondering if anyone has tried this and any issues they dealt with in regards to validating if the JSON is actually a DAG.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Label each node and make an edge list. That is, each node stores the nodes that it has edges to, for example:
You can store many kinds of graphs this way, not just DAGs, so you will need to post-process it to ensure that it has no loops.
Pick a node, DFS, if you see any node more than once it is not a DAG. Then remove all of the nodes you just saw and repeat with any remaining nodes. Do this until you find a loop or you’ve removed all of the nodes, in the latter case the graph is a DAG.
Note that this does not store parent nodes since that is redundant information. You can generate those after loading the graph if you need that data.