0% found this document useful (0 votes)
54 views2 pages

Depth Limited Search

The document outlines a Depth Limited Search (DLS) algorithm for traversing a graph represented by an adjacency list. It initializes a visited dictionary to track nodes and implements a function to search for a goal node within a specified depth limit. The algorithm explores nodes and checks for the goal, returning success or failure based on the search outcome.

Uploaded by

vennira8880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views2 pages

Depth Limited Search

The document outlines a Depth Limited Search (DLS) algorithm for traversing a graph represented by an adjacency list. It initializes a visited dictionary to track nodes and implements a function to search for a goal node within a specified depth limit. The algorithm explores nodes and checks for the goal, returning success or failure based on the search outcome.

Uploaded by

vennira8880
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Depth Limited Search

ADJ['S'] = ['2', '6']


ADJ['2'] = ['S', '3']
ADJ['3'] = ['2','8']
ADJ['G'] = ['10']
ADJ['6'] = ['S', '11']
ADJ['8'] = ['3', '13']
ADJ['10'] = ['G', '15']
ADJ['11'] = ['6', '12']
ADJ['12'] = ['11', '13', '17']
ADJ['13'] = ['8', '12']
ADJ['15'] = ['10', '20']
ADJ['17'] = ['12','22']
ADJ['19'] = ['20', '24']
ADJ['20'] = ['15','19']
ADJ['21'] = ['22']
ADJ['22'] = ['17','21','23']
ADJ['23'] = ['22', '24']
ADJ['24'] = ['19','23']
print (ADJ)
# keep track of visited nodes
visited = {str(i) : False for i in range(1,26)}
visited['S'] = False
visited['G'] = False

def dls(start, goal):


depth = 0
limit = 200
OPEN=[]
CLOSED=[]
OPEN.append(start)
visited["S"] = True
while OPEN != []: # Step 2
if depth<=limit:
current = OPEN.pop()
# visited[current] = False
if current == goal:
# CLOSED.append(current)
print("Goal Node Found")
# print(CLOSED)
return True
else:
# CLOSED.append(current)
lst = successors(current)
for i in lst:
# try to visit a node in future, if not already been t
o it
if(not(visited[i])):
OPEN.append(i)
visited[i] = True
depth +=1

else:
print("Not found within depth limit")
return False

return False

You might also like