from graph import LinkedDirectedGraph # Part 1: # Complete the…

Question Answered step-by-step from graph import LinkedDirectedGraph # Part 1: # Complete the… from graph import LinkedDirectedGraph# Part 1:# Complete the following function:def topologicalSort(graph):     #    stack = LinkedStack()   graph.clearVertexMarks()   for vertex in graph.vertices():       if (not vertex.isMarked()):           depthFirstSearch(graph, vertex, stack)   return stackdef depthFirstSearch(graph, vertex, stack):    vertex.setMark()    for neighbor in graph.neighboringVertices(vertex.getLabel()):        if (not neighbor.isMarked()):            depthFirstSearch(graph, neighbor, stack)    stack.push(vertex)graph = LinkedDirectedGraph()# The graph represents the following course prerequisites:# A requires nothing# B requires nothing# C requires A# D requires A, B, and C# E requires C# F requires B and D# G requires E and F# H requires C, F, and G# Part 2:# Add the vertices:# graph.addVertex(“A”)graph.addVertex(“B”)graph.addVertex(“C”)graph.addVertex(“D”)graph.addVertex(“E”)graph.addVertex(“F”)graph.addVertex(“G”)graph.addVertex(“H”)# Part 3:# Add the edges:# graph.addEdge(“A”, “C”, 0)graph.addEdge(“A”, “D”, 0)graph.addEdge(“B”, “D”, 0)graph.addEdge(“C”, “D”, 0)graph.addEdge(“C”, “E”, 0)graph.addEdge(“B”, “F”, 0)graph.addEdge(“D”, “F”, 0)graph.addEdge(“E”, “G”, 0)graph.addEdge(“F”, “G”, 0)graph.addEdge(“C”, “H”, 0)graph.addEdge(“F”, “H”, 0)graph.addEdge(“G”, “H”, 0)print(“Graph:”)print(graph)print()print(“Courses:”)# Part 4:# Display each vertex on a separate line:# for vertex in graph.getVertices():   print(str(vertex), sep = “”)print()print(“Prerequisites:”)# Part 5:# Display each edge on a separate line:# for edge in graph.edges():   print(str(edge), sep = “”)print()print(“One possible order to take the courses:”)# Part 6:# Display the courses in prerequisite (topological) order:# sortedVertices = topologicalSort(graph)for vertex in sortedVertices:       print(vertex, end=” “)print() Where am I wrong? Computer Science Engineering & Technology Python Programming CIS 214 Share QuestionEmailCopy link Comments (0)