0% found this document useful (0 votes)
2 views15 pages

AI LAB MANUAL Final

The document outlines a curriculum for an Artificial Intelligence Lab for IV Semester BCA 2025, consisting of programming tasks in Python. It includes implementations of various algorithms and problems such as Breadth First Search, Depth First Search, Water Jug problem, and Travelling Salesmen Problem. Each task is designed to enhance practical understanding of AI concepts through coding.

Uploaded by

archuniki2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

AI LAB MANUAL Final

The document outlines a curriculum for an Artificial Intelligence Lab for IV Semester BCA 2025, consisting of programming tasks in Python. It includes implementations of various algorithms and problems such as Breadth First Search, Depth First Search, Water Jug problem, and Travelling Salesmen Problem. Each task is designed to enhance practical understanding of AI concepts through coding.

Uploaded by

archuniki2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

IV Semester BCA 2025

Artificial Intelligence LAB

PART - A

1. Write a Program to implement Breadth First Search using Python.


2. Write a Program to implement Depth First Search using Python.
3. Write a Program to implement Best First Search using Python.
4. Write to implement a Program Water Jug problem using Python.
5. Write a Program to implement Tower of Hanoi using Python.

PART – B
6. Write a Program to implement Travelling Salesmen Problem using Python.
7. Write a Program to implement 8 Puzzle Problem using Python.
8. Write a Program to implement Latin Square Problem using Python.
9. Write a Program to solve Rat in a Maze using Backtracking using Python.
10. Write a Program to Solve Graph Coloring problem using Python.
Program 01: Write a Program to implement Breadth First Search using Python.

Output:
Program 02: Write a Program to implement Depth First Search using Python.

Output:
Program 03: Write a Program to implement Best First Search using Python.

Output:
Program 04: Write to implement a Program Water Jug problem using Python.

# This function is used to initialize the


# dictionary elements with a default value.
from collections import defaultdict

# jug1 and jug2 contain the value


# for max capacity in respective jugs
# and aim is the amount of water to be measured.
jug1, jug2, aim = 4, 3, 2

# Initialize dictionary with


# default value as false.
visited = defaultdict(lambda: False)

# Recursive function which prints the


# intermediate steps to reach the final
# solution and return boolean value
# (True if solution is possible, otherwise False).
# amt1 and amt2 are the amount of water present
# in both jugs at a certain point of time.
def waterJugSolver(amt1, amt2):

# Checks for our goal and


# returns true if achieved.
if (amt1 == aim and amt2 == 0) or (amt2 == aim and amt1 == 0):
print(amt1, amt2)
return True

# Checks if we have already visited the


# combination or not. If not, then it proceeds further.
if visited[(amt1, amt2)] == False:
print(amt1, amt2)

# Changes the boolean value of


# the combination as it is visited.
visited[(amt1, amt2)] = True

# Check for all the 6 possibilities and


# see if a solution is found in any one of them.
return (waterJugSolver(0, amt2) or
waterJugSolver(amt1, 0) or
waterJugSolver(jug1, amt2) or
waterJugSolver(amt1, jug2) or
waterJugSolver(amt1 + min(amt2, (jug1-amt1)),
amt2 - min(amt2, (jug1-amt1))) or
waterJugSolver(amt1 - min(amt1, (jug2-amt2)),
amt2 + min(amt1, (jug2-amt2))))
# Return False if the combination is
# already visited to avoid
# already visited to avoid repetition otherwise
# recursion will enter an infinite loop.
else:
return False

print("Steps: ")

# Call the function and pass the


# initial amount of water present in both jugs.
waterJugSolver(0, 0)

Output:
Program 5: Write a Program to implement Tower of Hanoi using Python without user input.

Output:
Program 5: Write a Program to implement Tower of Hanoi using Python with user input.

Output:
Program 6: Write a Program to implement Travelling Salesmen Problem using Python.

Output:
7. Write a Program to implement 8 Puzzle Problem using Python.
Output:
PROGRAM 08: Write a Program to implement Latin Square Problem using Python

Output:
Program 09: Write a Program to solve Rat in a Maze using Backtracking using Python
Program 09 Output:
Program 10: Write a Program to Solve Graph Coloring problem using Python.

OUTPUT:

You might also like