Question: Here is my code and instruction Please help me to solve this problem Thank you Goal In Module 6, we discussed the Graph data structure.



Here is my code and instruction
Please help me to solve this problem
Thank you
Goal In Module 6, we discussed the Graph data structure. Since the graph is a non-linear structure, there is no unique traversal. Nodes can be found using Breadth-First Search (visit the sibling nodes before visiting the child nodes) and Depth-first search (visit the child nodes before visiting the sibling nodes). Based on the implementation of the Graph data structure discussed during our lecture (provided in the starter code) 1. Create the method bfs(start). This method takes the key of the starting node and performs Breadth-first search in an instance of the class Graph. This method must return a list that contains the order in which the nodes where accessed during the search (following alphabetical order when discovering nodes). You must use your queue code from LAB 10 rder Su 0 re the assignment 2. Create the method dfs(start). This method takes the key of the starting node and performs Depth-first search in an instance of the class Graph. This method must return a list that contains the order in which the nodes where accessed during the search (following alphabetical order when discovering nodes). You must us ack code fro order to produce vour result. If you don't use the stack, vour will not receive credit for the sSignrme Grading Notes A random instance of the Graph class (directed or undirected, weighted or unweighted) will be created and the bfs and dfs methods will be called on 4 different starting nodes for 12.5 pts each. Make sure you use the Graph data structure provided in the starter code, otherwise, no credit will be given. Vertices and edges will be provided in random order (non-alphabetical order). The final result should be only the one provided by following alphabetical order - EXAMPLE Note that this is only an example, the fact that you code produces the example's output does not ensure your code works properly. Test your code with several examples! C': 'F E'B, 'G' >g-Graph (g1) >>>g.bfs('A') l A', 'B >>>g.dfs('A') >g-Graph (g2) >>>g.bfs('A') >>>g.dfs ('A') >g-Graph (g3) >>>g.bfs('A') >>>g.dfs('A') class Graph: def -init-(self, graph-repr=None): if graph_repr is None: else:self.vertList - graph_repr if key not in self, vertList: self.vertList = {} def addVertex(self, key) self . ve rt List lkey] = return self.vertList [] def addEdge(self, frm,to,cost-1) if frm not in self.vertList if to not in self.vertList self.vertList [frm].append (to, cost)) self.addVertex(frm) self.addVertex to) return self.vertList def bfs (self, start) # Your code starts here def dfs(self, start) # Your code starts here Goal In Module 6, we discussed the Graph data structure. Since the graph is a non-linear structure, there is no unique traversal. Nodes can be found using Breadth-First Search (visit the sibling nodes before visiting the child nodes) and Depth-first search (visit the child nodes before visiting the sibling nodes). Based on the implementation of the Graph data structure discussed during our lecture (provided in the starter code) 1. Create the method bfs(start). This method takes the key of the starting node and performs Breadth-first search in an instance of the class Graph. This method must return a list that contains the order in which the nodes where accessed during the search (following alphabetical order when discovering nodes). You must use your queue code from LAB 10 rder Su 0 re the assignment 2. Create the method dfs(start). This method takes the key of the starting node and performs Depth-first search in an instance of the class Graph. This method must return a list that contains the order in which the nodes where accessed during the search (following alphabetical order when discovering nodes). You must us ack code fro order to produce vour result. If you don't use the stack, vour will not receive credit for the sSignrme Grading Notes A random instance of the Graph class (directed or undirected, weighted or unweighted) will be created and the bfs and dfs methods will be called on 4 different starting nodes for 12.5 pts each. Make sure you use the Graph data structure provided in the starter code, otherwise, no credit will be given. Vertices and edges will be provided in random order (non-alphabetical order). The final result should be only the one provided by following alphabetical order - EXAMPLE Note that this is only an example, the fact that you code produces the example's output does not ensure your code works properly. Test your code with several examples! C': 'F E'B, 'G' >g-Graph (g1) >>>g.bfs('A') l A', 'B >>>g.dfs('A') >g-Graph (g2) >>>g.bfs('A') >>>g.dfs ('A') >g-Graph (g3) >>>g.bfs('A') >>>g.dfs('A') class Graph: def -init-(self, graph-repr=None): if graph_repr is None: else:self.vertList - graph_repr if key not in self, vertList: self.vertList = {} def addVertex(self, key) self . ve rt List lkey] = return self.vertList [] def addEdge(self, frm,to,cost-1) if frm not in self.vertList if to not in self.vertList self.vertList [frm].append (to, cost)) self.addVertex(frm) self.addVertex to) return self.vertList def bfs (self, start) # Your code starts here def dfs(self, start) # Your code starts here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
