We have the assumption that the graph is directed, unweighted and connected.
Depth frst traversal can be used to detect a cycle in the graph. DFS for a connected graph produces a tree. There is a cycle in a graph only if there is a back edge present in the graph.( back edge means loop in the graph from a particular node to itself).
Algorithm/ pseudocode:
1. Create the graph along with allowed directions.
2. Create a recursive function that initializes current index/ vertex and one recursion stack.
3. Mark the current node as visited and also mark the index in the stack.
4. Find all the vertices which are not visited( in the direction allowed by the graph). Recursively, call the function for those vertices, if the recursive function returns true, return true.
5. If the adjacent vertices are already marked in the recursion stack then return true.
6. Create a wrapper class, That calls the recursive function for all the vertices and if any function returns true, return true. Else if for all vertices the function returns false return false.
(10) Sketch an algorithm, in pseudocode, to find and return a shortest cycle in a graph,...
You are managing a large scale construction project with hundreds of subprojects, some which have to be completed before others can begin whereas some subprojects can be carried out simultaneously. The project and its subprojects, and the presence of dependencies between subprojects (which subprojects have to be done before which), can be modeled as a connected unweighted directed graph with nodes representing subprojects and directed edges representing dependencies. 42. Which of the following algorithms will allow you to determine if...