Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

PROGRAM:

from collections import deque


def bfs(start_node, goal_node, neighbor_func):
visited = set()
queue = deque([(start_node, [start_node])])
while queue:
current_node, path = queue.popleft()
if current_node == goal_node:
return path
visited.add(current_node)
for neighbor in neighbor_func(current_node):
if neighbor not in visited:
queue.append((neighbor, path + [neighbor]))
visited.add(neighbor)
return None
def neighbor_func(node):
return [node+1, node-1, node*2]
start_node = 1
goal_node = 10
shortest_path = bfs(start_node, goal_node, neighbor_func)
if shortest_path:
print(f"Shortest path from {start_node} to {goal_node}: {shortest_path}")
else:
print(f"No path from {start_node} to {goal_node} found.")

OUTPUT:

RESULT:
PROGRAM:

# Define a function for DFS


def dfs(graph, visited, vertex):
visited[vertex] = True
print(vertex, end=' ')
for neighbor in range(len(graph)):
if graph[vertex][neighbor] == 1 and not visited[neighbor]:
dfs(graph, visited, neighbor)
# Example usage
graph = [ [0, 1, 1, 0, 0],
[1, 0, 0, 1, 1],
[1, 0, 0, 0, 1],
[0, 1, 0, 0, 1],
[0, 1, 1, 1, 0]
]
visited = [False] * len(graph)
start_vertex = 0
dfs(graph, visited, start_vertex)

OUTPUT:

RESULT:
PROGRAM:

from sklearn.datasets import load_iris


from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load the iris dataset
iris = load_iris()
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.3,
random_state=42)
# Create a Gaussian Naive Bayes model
gnb = GaussianNB()
# Train the model on the training set
gnb.fit(X_train, y_train)
# Use the model to make predictions on the testing set
y_pred = gnb.predict(X_test)
# Calculate the accuracy of the model
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:",accuracy)

OUTPUT:

RESULT:
PROGRAM:

from collections import deque


def bfs(start_node, goal_node, neighbor_func):
visited = set()
queue = deque([(start_node, [start_node])])
while queue:
current_node, path = queue.popleft()
if current_node == goal_node:
return path
visited.add(current_node)
for neighbor in neighbor_func(current_node):
if neighbor not in visited:
queue.append((neighbor, path + [neighbor]))
visited.add(neighbor)
return None
def neighbor_func(node):
return [node+1, node-1, node*2]
start_node = 1
goal_node = 10
shortest_path = bfs(start_node, goal_node, neighbor_func)
if shortest_path:
print(f"Shortest path from {start_node} to {goal_node}: {shortest_path}")
else:
print(f"No path from {start_node} to {goal_node} found.")

OUTPUT:

RESULT:
PROGRAM:

# Define a function for DFS


def dfs(graph, visited, vertex):
visited[vertex] = True
print(vertex, end=' ')
for neighbor in range(len(graph)):
if graph[vertex][neighbor] == 1 and not visited[neighbor]:
dfs(graph, visited, neighbor)
# Example usage
graph = [ [0, 1, 1, 0, 0],
[1, 0, 0, 1, 1],
[1, 0, 0, 0, 1],
[0, 1, 0, 0, 1],
[0, 1, 1, 1, 0]
]
visited = [False] * len(graph)
start_vertex = 0
dfs(graph, visited, start_vertex)

OUTPUT:

RESULT:
PROGRAM:

from sklearn.datasets import load_iris


from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# Load the iris dataset
iris = load_iris()
# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(iris.data, iris.target, test_size=0.3,
random_state=42)
# Create a Gaussian Naive Bayes model
gnb = GaussianNB()
# Train the model on the training set
gnb.fit(X_train, y_train)
# Use the model to make predictions on the testing set
y_pred = gnb.predict(X_test)
# Calculate the accuracy of the model
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:",accuracy)

OUTPUT:

RESULT:
Exp no:
IMPLEMENTATION OF UNINFORMED SEARCH
Date:
USING BREADTH FIRST SEARCH (BFS)
Exp no:
IMPLEMENTATION OF UNINFORMED SEARCH
Date:
USING DEPTH FIRST SEARCH (DFS)
Exp no:
IMPLEMENTATION OF NAÏVE BAYES MODEL
Date:
Exp no:
IMPLEMENTATION OF UNINFORMED SEARCH
Date:
USING BREADTH FIRST SEARCH (BFS)
Exp no:
IMPLEMENTATION OF UNINFORMED SEARCH
Date:
USING DEPTH FIRST SEARCH (DFS)
Exp no:
IMPLEMENTATION OF NAÏVE BAYES MODEL
Date:

You might also like