Aiml Exp 2 Adarsh Pandey
Aiml Exp 2 Adarsh Pandey
Experiment-1.2
Student Name: ADARSH PANDEY UID: 21BCS2027
Branch: CSE Section/Group: 906-A
Semester: 5TH Date of Performance: 17/8/23
Subject Name: AIML Subject Code: 21CSH-316
1. Aim: Implement the DFS algorithm and analyze its performance and
characteristics.
3. Pseudo Code:
function DFS(graph, current, goal, visited): if current equals
goal: return [current] # Path found, return the single-node
path
4. Code:
def dfs(graph, start, goal):
stack = [(start, [start])]
visited = set()
while stack:
current, path = stack.pop()
if current == goal:
return path
if current not in visited:
visited.add(current)
for neighbor in graph[current]:
if neighbor not in visited:
stack.append((neighbor,
path + [neighbor]))
return None
graph = {
'A': ['B', 'C'],
'B': ['A', 'D', 'E'],
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
5. Output:
6. Learning Outcomes:
The learning outcomes of this experiments are:
• Understood how DFS can be used to find paths between nodes in a
graph.
• Learnt how DFS backtracks when exploring paths.
• Understood the concept of DFS.
• Ability to analyze algorithmic performance and optimize graph
traversal strategies.