Question: The DFSGraph uses a time attribute to note when a vertex if first encountered (discovery attribute) in the depthfirst search and when a vertex in
The DFSGraph uses a time attribute to note when a vertex if first encountered (discovery attribute) in the depthfirst search and when a vertex in backtracked through (finish attribute). Consider the prerequisite graph for Bobs Computer Science courses.
a.) Assume that the for-loops alway iterate through the vertexes alphabetically (e.g., CS 1410, CS 1510, CS 1520, CS 1800,...) by their id. Write on the above graph the discovery and finish times assigned to each vertex by executing the dfs method.

Question 9. (5 points) The DFSGraph uses a time attribute to note when a vertex if first encountered (discovery attribute) in the depth- first search and when a vertex in backtracked through (finish attribute). Consider the prerequisite graph for Bob's Computer Science courses. from graph import Graph CS 3140 class DFSGraph (Graph): def init (self): super(). init self.time = 0 CS 4410 () CS 1410 CS 3470 CS 4400 def dfs (self): for aVertex in self: aVertex.setColor('white') aVertex.setPred (-1) for aVertex in self: if aVertex.getColor() == 'white': self.dfsvisit (aVertex) CS 1510 CS 1520 CS 2530 CS 1800 CS 2720 def dfsvisit (self, startVertex): startVertex.setColor('gray') self.time += 1 startVertex.setDiscovery (self.time) for nextVertex in startVertex.getConnections(): if nextVertex.getColor() == 'white': nextVertex.setPred (startVertex) self.dfsvisit (nextVertex) startVertex.setColor('black') self.time += 1 startVertex. setFinish (self.time) CS 3530 CS 4550 a) Assume that the for-loops alway iterate through the vertexes alphabetically (e.g., CS 1410, CS 1510, CS 1520, CS 1800,...) by their id. Write on the above graph the discovery and finish times assigned to each vertex by executing the dfs method. Question 9. (5 points) The DFSGraph uses a time attribute to note when a vertex if first encountered (discovery attribute) in the depth- first search and when a vertex in backtracked through (finish attribute). Consider the prerequisite graph for Bob's Computer Science courses. from graph import Graph CS 3140 class DFSGraph (Graph): def init (self): super(). init self.time = 0 CS 4410 () CS 1410 CS 3470 CS 4400 def dfs (self): for aVertex in self: aVertex.setColor('white') aVertex.setPred (-1) for aVertex in self: if aVertex.getColor() == 'white': self.dfsvisit (aVertex) CS 1510 CS 1520 CS 2530 CS 1800 CS 2720 def dfsvisit (self, startVertex): startVertex.setColor('gray') self.time += 1 startVertex.setDiscovery (self.time) for nextVertex in startVertex.getConnections(): if nextVertex.getColor() == 'white': nextVertex.setPred (startVertex) self.dfsvisit (nextVertex) startVertex.setColor('black') self.time += 1 startVertex. setFinish (self.time) CS 3530 CS 4550 a) Assume that the for-loops alway iterate through the vertexes alphabetically (e.g., CS 1410, CS 1510, CS 1520, CS 1800,...) by their id. Write on the above graph the discovery and finish times assigned to each vertex by executing the dfs method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
