-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #394 from sifa123/patch-2
Create Iterative Deepening Search.py
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
Artificial Intelligence/Create Iterative Deepening Search.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |