Skip to content

Commit

Permalink
Merge pull request #394 from sifa123/patch-2
Browse files Browse the repository at this point in the history
Create Iterative Deepening Search.py
  • Loading branch information
Kavya-24 authored Oct 6, 2024
2 parents f3824af + b9e3649 commit 512db65
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Artificial Intelligence/Create Iterative Deepening Search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
graph = {
'1': ['2', '3', '4'],
'2': ['5', '6'],
'3': ['7', '8'],
'4': ['9'],
'5': ['10', '11'],
'6': [],
'7': ['12'],
'8': [],
'9': ['13'],
'10': [],
'11': ['14'],
'12': [],
'13': [],
'14': []
}
def DFS(currentNode,destination,graph,maxDepth):
print("Checking for destination",currentNode)
if currentNode==destination:
return True
if maxDepth<=0:
return False
for node in graph[currentNode]:
if DFS(node,destination,graph,maxDepth-1):
return True
return False

def IDDFS(currentNode,destination,graph,maxDepth):
for i in range(maxDepth):
if DFS(currentNode,destination,graph,i):
return True
return False

if not IDDFS('1','14',graph,5):
print("Path is not available")
else:
print("Path Exists")

0 comments on commit 512db65

Please sign in to comment.