Question: A directed graph is call a Directed Acyclic Graph ( DAG ) if it does have any cycle. For example, figure 1 does not have
A directed graph is call a Directed Acyclic Graph DAG if it does have any cycle. For example, figure does not have any cycle in all its paths, therefore, it is DAG graph. While, figure is cyclic graph not DAG since there is a cycle
rigure : Lyclic rapI
Write a Python program that reads graph information from a file and check if it is DAG or not.
Write a function that reads and graph information from an input file and store it a dictionary:
a Reads the edges for a graph from an input file where each line has two strings A and to represent a directed edge from node to node B Note that the number of nodes is not specified.
tableGraphtxt File,Graphtxt Filea bA Ba cCEa eB CadE DcdE Fb dD Bdece
b The graph information is saved in a dictionary myGraph to maintain the name string and list of adjacent nodes for each node in a graph a: bce The following table shows the adjacency nodes in figure
tableNode Name keyAdjacent Nodes valuea
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
