Question: Create an application in C + + called main.cpp that , given a directed graph without cycles ( DAG ) , with n vertices
Create an application in Ccalled "main.cppthat given a directed graph without cyclesDAGwith n vertices and frames, says whether the graph is a tree and displays its topological order. Use the following functions
loadGraph
Description: Load the edges of the graph and store them in an Adjacency List
Input: Two positive integers:
nNumber of Vertices
mNumber of Arcs
m "letters" representing start and end of each arc, two per line
start and end of each arc
Output: Nothing
Precondition: n and m are positive integers
Postcondition: Nothing
isTree
Description: Tell whether the Directed GraphDAGis a tree or not
Input: The Adjacency list, nVerticesand mArcspointer
Output: A boolean value telling whether the graph is a tree or not.
Precondition: The graph must be correctly loaded in the adjacency list, n and m must be positive integers.
Postcondition: Nothing
topologicalSort
Description: Sort the nodes of the DAG using Kahn's algorithm
Input: The adjacency list, nVerticesand mArcspointer
Output: Nothing
Precondition: The graph must be correctly loaded in the adjacency list, n and m must be positive integers.
Postcondition: Nothing
The input to the program is the number of verticesnthe number of arcsmas well as each of the arcs.
The output isfirst a booleantruefalsethat tells whether the graph is a tree or not, followed by the topological sort of the DAGfollowing Kahn's algorithmwriting one node at a time, followed by a space. After the last node, there is also a blank space and a line break at the end
Input example:
A D
B D
C A
C B
D G
D H
E A
E D
E F
F J
F K
G I
H I
H J
I L
J L
J M
K J
Output example:
false
C E B A F D K G H I J L M
All the functionalities must be correctly aligned and documented.
As part of the documentation, the complexity of each one of them must be included.
The application must request the user for the number of verticesnthe number of nodesmas well as each of the arcs.
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
