From b9e36499d427c163102cbb8507e7d4063c02bfd0 Mon Sep 17 00:00:00 2001 From: Sefat Siddiquea Sifa <63462931+sifa123@users.noreply.github.com> Date: Sat, 5 Oct 2024 22:12:34 +0600 Subject: [PATCH] Create Iterative Deepening Search.py --- .../Create Iterative Deepening Search.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Artificial Intelligence/Create Iterative Deepening Search.py diff --git a/Artificial Intelligence/Create Iterative Deepening Search.py b/Artificial Intelligence/Create Iterative Deepening Search.py new file mode 100644 index 0000000..1f1ffb2 --- /dev/null +++ b/Artificial Intelligence/Create Iterative Deepening Search.py @@ -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")