ACI - Gaurav
ACI - Gaurav
Submitted By:
Submitted To:
Gaurav Dr. Nidhi Srivastava
Roll. No:22DS16 Asst. Professor
B.Tech(CSE-DS)-5th sem CSE Department
INDEX
Program :
visited.add(current)
print(f"Visiting node:
{current}")
for neighbor in
graph[current]: if neighbor
not in visited:
pq.put((h[neighbor], neighbor))
print("Goal not
reachable.") return False
graph = {
'A': ['B', 'C'],
'B': ['D', 'E'],
'C': ['F',
'G'], 'D': [],
'E': [],
'F': [],
'G': []
}
h= {
'A': 3,
'B': 2,
'C': 4,
'D': 6,
'E': 1,
'F': 5,
'G': 0
}
Output :
EXPERIMENT-2
Program :
ifarr[mid] == target:
return mid
elifarr[mid] < target:
low = mid + 1
else:
high = mid - 1
return 1
if result != 1:
print(f"Element {target} found at index {result}")
print(f"Element {target} found at position {result + 1}")
else:
print(f"Element {target} not found in the array")
output:
EXPERIMENT-3
Program :
arr = [22, 13, 45, 87, 29, 69, 99, 12, 55]
print(arr)
target = int(input("enter the element :
if result != 1:
print(f"Element {target} found at index {result}")
print(f"Element {target} found at position {result + 1}")
else:
print(f"Element {target} not found in the array")
Output :
EXPERIMENT :- 04
AIM :- Write a program for heuristic search using python (using BSF)
PROGRAM:-
graph = {
'5' : ['3','7'],
'3' : ['2', '4'],
'7' : ['8'],
'2' : [],
'4' : ['8'],
'8' : []
}
visited =
[] queue =
[]
def bfs(visited, graph,
node): visited.append(node)
queue.append(node)
while queue:
m = queue.pop(0)
print (m, end = " ")
OUTPUT :-
EXPERIMENT :- 05
PROGRAM :-
graph = {
'5' : ['3','7'],
'3' : ['2', '4'],
'7' : ['8'],
'2' : [],
'4' : ['8'],
'8' : []
}
visited = set()
OUTPUT :-
EXPERIMENT :- 06
PROGRAM :-
import random
def objective_function(x):
return -(x ** 2) + 10 # Simple function with a peak atx = 0
# Parameters
initial_solution = random.uniform(- 10, 10)
step_size = 0.1
iterations = 100
OUTPUT
:-
EXPERIMENT :- 07
PROGRAM :-
import heapq
while frontier:
cost, node =
heapq.heappop(frontier) if node ==
goal:
return cost
if node not in explored:
explored[node] =
cost
for neighbor, edge_cost in graph[node]:
heapq.heappush(frontier, (cost + edge_cost,
neighbor))
return float("inf")
# Example graph
graph = {
'A': [('B', 1), ('C', 4)],
'B': [('D', 2), ('E', 5)],
'C': [('F', 3)],
'D': [], 'E': [('F', 1)], 'F': []
}
# Run the search
print(uniform_cost_search(graph, 'A',
'F'))
OUTPUT :-
EXPERIMENT :- 08
PROGRAM :-
# Build a simple
ANN model =
Sequential([
Dense(64, input_dim=20, activation='relu'), # Hidden layer
Dense(3, activation='softmax') # Output layer for 3 classes
])
OUTPUT :-
EXPERIMENT :- 09
PROGRAM :-
PROGRAM :-
# Make predictions
y_pred = model.predict(X_test)