Professional Documents
Culture Documents
715-Sanket Dalvi-Practical 5
715-Sanket Dalvi-Practical 5
IT
Roll No:- 715 Div:- A
PRACTICAL NO:- 5
Practical 5(A):-
Aim:- Program to solve the problem of given graph traversal through depth first
search.
Source Code:-
print("Program to solve the below given graph travesal problem through Depth
First search")
explorednode = set()
if startnode is None:
return
return
explorednode.add(startnode)
return explorednode
sanket_graph_one={
'A':set(['B','C']),
'B':set(['D','E']),
'C':set(['F']),
'D':set([]),
'E':set(['F']),
'F':set([])}
sanket_graph_two ={
'0':set(['1','2']),
'1':set(['4','5']),
'2':set(['3','5']),
'3':set(['6']),
'4':set(['7']),
'5':set(['3','6']),
'7':set([])
sanket_graph_three = {
'Amy': set(['Jack','Jill','Joana']),
'Jack': set(['Lucy']),
'Lucy': set([]),
'Jill': set(['Cindy','Camilla']),
'Joana': set(['Will']),
'Camilla': set([]),
'Will': set([]),
'Eleven': set([]),
'Emma': set([])
search_graph = sanket_graph_three
print("\n solution path for the above problem using depth first graph is as follows
: \n")
explorednode = explorednode)
Output:-
Source Code:-
First Search")
print("searching access depth --> Left to Right --> all levels at Time")
explorednode = []
nodequeue = [startnode]
currentnode = nodequeue.pop(0)
explorednode.append(currentnode)
adjancentnode = graph[currentnode]
return explorednode
sanket_graph_one = dict()
sanket_graph_one['H'] = ['C']
sanket_graph_two = {
'Lucy': set(['Jack']),
'Camilla': set(['Jill']),
'Will': set(['Joana']),
'Eleven': set(['Cindy']),
'Emma': set(['Cindy'])
search_graph = sanket_graph_two
start_search_at = 'Amy'
print("\n Solution path For The Above Problem Using Breadth First Search is..\n")
BreadthFirstSearch(graph=search_graph, startnode=start_search_at,
explorednode=explorednode)