Aiml 1,2
Aiml 1,2
DATE:
PROGRAM TO APPLY DEPTH FIRST SEARCH
AIM:
graph={'5':['3','7'],'3':['2','4'],'7':['8'],'2':[],'4':['8'],'8':[]}
visited=set()
def dfs(visited,graph,node):
print(node)
visited.add(node)
dfs(visited,graph,neighbour)
RESULT:
EXP NO:1(B)
DATE:
PROGRAM TO APPLY BREADTH FIRST SEARCH
AIM:
To write a python program to calculate breadth first search.
ALGORITHM:
PROGRAM:
graph={'5':['3','7'],'3':['2','4'],'7':['8'],'2':[],'4':['8'],'8':[]}
visited=[]
queue=[]
def dfs(visited,graph,node):
visited.append(node)
queue.append(node)
while queue:
m=queue.pop()
print(m)
for neighbor in graph[m]:
if neighbor not in visited:
visited.append(neighbor)
queue.append(neighbor)
print(“following is the breadth first search”)
bfs(visited,graph,’5’)
OUTPUT:
RESULT:
Thus ,the program was executed and output was verified
successfully.
EXP NO:2(A)
DATE:
IMPLEMENTATION OF INFORMED SEARCH ALGORITHM
a)A* ALGORITHM
AIM:
To write a python program for implementation of informed search algorithm
using A* algorithm.
ALGORITHM:
PROGRAM:
class Graph:
self.adjac_lis = adjac_lis
return self.adjac_lis[v]
return H[n]
open_lst = set([start])
closed_lst = set([])
poo = {}
poo[start] = 0
par = {}
par[start] = start
n = None
for v in open_lst:
if n == None:
return None
if n == stop:
reconst_path = []
while par[n] != n:
reconst_path.append(n)
n = par[n]
reconst_path.append(start)
reconst_path.reverse()
return reconst_path
open_lst.add(m)
par[m] = n
else:
par[m] = n
if m in closed_lst:
closed_lst.remove(m)
open_lst.add(m)
open_lst.remove(n)
closed_lst.add(n)
OUTPUT:
EXP NO:2(B)
DATE:
MEMORY BOUNDED – A*
AIM:
Step 5: Check for the goal node amd return present or not.
graph={‘A’:[‘B’,’C’},’B’:[‘D’,’E’],’C’:[‘F’,’G’],’D’:[‘H’,’J’],’E’:[‘J’,’K’],’F’:[‘L’,’M’],’G’:
[‘N’,’O’],’H’:[],’I’:[],’J’:[],’K’:[],’L’:[],’M’:[],’N’:[],’O’:[]}
def ma(start,goal,path,level,maxD):
path.append(start)
if(start==goal)
return path
else:
if(level==maxD):
return False
if ma(child,goal,path,level+1,maxD):
return path
path.pop()
return False
start=’A’
path=list()
res=ma(start,goal,path,1,maxD)
if(res):
print(“path”,path)
else:
print(“No path available for the goal node in the given depth limit”)
OUTPUT:
RESULT:
Thus,the program was executed and output was verified successfully.