Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Programming Based on the BFS code given in attachment, allow user to create their own graph by entering vertices and edges of the

Python 3 Programming

image text in transcribed

Based on the BFS code given in attachment, allow user to create their own graph by entering vertices and edges of the graph

1. Use the graph information entered by user to implement DFS traversal, let user specify the source node and your code should print the traversal order.

2. Use the concept of traversal learn in BFS, create a GUI to implement DFS search using class based object.

class graphBFS (object) def init (self,graph): self.graph graph self.visited - [1 self.visitQueue[ def bfs (self, sourceNode, targetNode) self.visited - [1 self.visitQueue[ self.visited.append (sourceNode) self.visitQueue.append (sourceNode) found False while self.visitQueue and found is False: sourceNode = self.visitQueue [O] self.visitQueue.remove (sourceNode) print (sourceNode) Eor adjacent in self.graph [sourceNode]: if adjacent not in self.visited: self.visitQueue.append (adjacent) self.visited.append (adjacent) if adjacent is targetNode: print (adjacent) found = True break if found is False: print ("Item not found!") BFSgraphBFS ( E:'D'1 BFS.bfs 'A, F) class graphBFS (object) def init (self,graph): self.graph graph self.visited - [1 self.visitQueue[ def bfs (self, sourceNode, targetNode) self.visited - [1 self.visitQueue[ self.visited.append (sourceNode) self.visitQueue.append (sourceNode) found False while self.visitQueue and found is False: sourceNode = self.visitQueue [O] self.visitQueue.remove (sourceNode) print (sourceNode) Eor adjacent in self.graph [sourceNode]: if adjacent not in self.visited: self.visitQueue.append (adjacent) self.visited.append (adjacent) if adjacent is targetNode: print (adjacent) found = True break if found is False: print ("Item not found!") BFSgraphBFS ( E:'D'1 BFS.bfs 'A, F)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke, David Auer

11th Edition

B003Y7CIBU, 978-0132302678

More Books

Students also viewed these Databases questions