0% found this document useful (0 votes)
4 views31 pages

AI Exp file (1)

The document outlines various experiments focused on search algorithms and their applications in problem-solving, including measuring water with jugs, solving the 8-puzzle, and implementing BFS and DFS algorithms. It emphasizes the importance of understanding state-space search, optimization techniques, and graph theory concepts, while also detailing practical implementations using programming languages like Python. Each experiment concludes with insights gained and the relevance of the techniques in real-world scenarios.

Uploaded by

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

AI Exp file (1)

The document outlines various experiments focused on search algorithms and their applications in problem-solving, including measuring water with jugs, solving the 8-puzzle, and implementing BFS and DFS algorithms. It emphasizes the importance of understanding state-space search, optimization techniques, and graph theory concepts, while also detailing practical implementations using programming languages like Python. Each experiment concludes with insights gained and the relevance of the techniques in real-world scenarios.

Uploaded by

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

Index

S.No Aim Sign


Experiment 1
AIM –

To measure 4 litres of water using a small jug with a capacity of 3 litres and a
large jug with a capacity of 5 litres, demonstrating the use of search
algorithms in solving the problem.

Theory –

The problem of measuring a specific amount of water using two


different sizes of water containers is one classic problem in Artificial
Intelligence. Search algorithms in AI cover methods that can be applied
to navigate a set of possibilities toward a goal state. This problem could
be solved by a mere state space search, where each state defines the
amount of water in both jugs.

The states of the problem are represented in pairs (x, y) by the amount in
the jug of 3 litres and the 5-liter jug, respectively. We want to attain the
state that one of the jugs has at least 4 litres of water. The search can be
carried out using three types of elementary operations:
Pour water between two jugs until either the first one is empty or the
second one is full.
Program –
OUTPUT –

LEARNING –
Through the program, we learned how search algorithms can be applied towards solving
real-world problems. We were able to solve the two jugs water measuring problem by
exhaustively searching through all its possible states and following a simple decision process
to reach a desired result.
This practical exercise illustrates the importance of state-space search in AI by showing
that even with only simple loops and conditionals, one can put together an algorithm that
convincingly solves a problem.

CONCLUSION –

The generalized program clearly shows how search algorithms can be used to
measure a specific amount of water with any two jugs of different capacities. It
also strengthens our knowledge in the area of search algorithms while underlining
the importance of developing flexible solutions that could work with a whole range
of inputs.
Experiment 2
AIM –

The 8-puzzle problem involves the movement of tiles on a 3x3 grid from a given
initial configuration to a specified goal configuration in the fewest possible moves.
There are numbered tiles from 1 to 8 with an open space that allows the sliding
of tiles into this open space. The task is to find a sequence of moves that
transforms the initial state of the puzzle into the goal state. Ends.

Theory –

One of the most famous puzzles is the 8-puzzle, which features a 3 × 3 grid with
one space empty and nine tiles numbered from 1 to 8. The latter can be slid into
the empty space, allowing them to be rearranged. The problem will consist of
changing the puzzle from the given configuration to a target configuration with a
series of valid movements.

Thus, one is to find the sequence of moves that would bring the puzzle into its
goal configuration. So, the solution implies an examination of various move
sequences, usually represented by a tree whose branches would correspond to the
possible move from some state. Some other efficient methods of solution are
algorithms of Breadth- First Search and А*, which search through prospective
solutions in an orderly fashion.
PROGRAM –
OUTPUT –

LEARNING –

Problem-Solving Skills: The 8-puzzle enhances one's ability in logical thinking and
problem-solving skills by requiring the identification of the correct sequence of
steps towards the goal configuration.
State-Space Search: The concept it introduces is a consideration of all feasible states
in finding an optimum solution, wherein each configuration takes the form of a
particular state.

It provides an algorithmic thinking process that, in a very simple way, the puzzle
shows how search algorithms like BFS or A* could be employed in scientific and
engineering applications to systematically explore possibilities for the solution of
complex problems.

Optimization: The need is stressed that finding a solution is not all; instead, one
needs to find the most efficient solution, which gives an optimum number of moves
needed to achieve this.

Therefore, the 8-puzzle becomes a very good exercise toward developing


computational thinking and understanding search algorithms.

CONCLUSION –

The 8-puzzle problem is a very straightforward and effective technique through


which to learn the rudiments in problem-solving and designing strategies for
related algorithms. Solving this puzzle actually deepens the basic understanding of
state-space explorations, search algorithms, and optimization techniques. Still, the
methods applied for 8-puzzle solving are relevant to far more serious problems
within the computer science and artificial intelligence field. At the end of the day,
it brings useful lessons in logical reasoning, perseverance, and finding efficient
solutions.
Experiment - 3

Breadth-First Search (BFS) is a graph traversal algorithm that explores all


the nodes in a graph level by level, starting from a given source node. It
is a popular algorithm for searching graphs, finding shortest paths, and
solving puzzles.
How does BFS work?
1. Choose a starting node: Select a node in the graph to start the
search from.
2. Create a queue: Initialize a queue data structure to hold nodes to
be visited.
3. Mark the starting node as visited: Add the starting node to the
queue and mark it as visited.
4. Explore neighbors: Dequeue a node from the queue and explore
its neighbors. For each neighbor:
• If the neighbor is not visited, mark it as visited and add it to
the queue.
• If the neighbor is already visited, skip it.
5. Repeat step 4: Continue dequeuing nodes and exploring their
neighbors until the queue is empty.
6. Return the traversal order: The order in which nodes were visited
is the BFS traversal order.
PROGRAM –
OUTPUT –
LEARNING –

Implementing BFS develops algorithmic thinking, problem-solving skills, and


programming expertise. We'll learn to work with graphs, queues, and sets, and
understand graph theory concepts like nodes, edges, and adjacency. We'll improve
your programming skills, including writing efficient and readable code, and develop a
systematic approach to solving problems. BFS has real-world applications in social
network analysis, web crawling, and network topology analysis. By implementing
BFS, we'll develop patience, persistence, and communication skills, and gain a
deeper understanding of computer science concepts.

CONCLUSION –

In conclusion, implementing the Breadth-First Search algorithm is a valuable learning


experience that offers a wide range of benefits. By mastering BFS, we'll develop
essential skills in algorithmic thinking, problem-solving, and programming. We'll gain
a deeper understanding of graph theory and its applications in real-world problems.
With BFS, we’ll be able to tackle complex challenges and develop a systematic
approach to solving problems. By applying BFS to real-world scenarios, we'll become
a more proficient programmer and a more effective problem-solver, equipped to
tackle even the most daunting challenges in computer science.
Experiment - 4

Write a program for DFS algorithm implementation.

Theory –

Depth-First Search (DFS) is a graph traversal algorithm that explores a graph or tree
by visiting a node and then visiting all of its neighbors before backtracking. It uses a
stack to keep track of nodes to visit, and is often used to search for a path between
two nodes.

It is a graph traversal algorithm that explores a graph or tree by visiting a node and
then visiting all of its neighbors before backtracking. It uses a stack to keep track of
nodes to visit. The algorithm starts at a given node (root) and explores as far as
possible along each branch before backtracking. It is used to search for a path
between two nodes, detect cycles, and perform topological sorting. DFS has a time
complexity of O(|V| + |E|) and a space complexity of O(|V|), making it efficient for
searching large graphs.

This program defines a graph class that represents a graph using an adjacency list.
The add edge method adds an edge between two vertices, and the DFS method
performs a depth-first search starting from a given vertex.

The DFS helper method is a recursive helper function that performs the actual DFS
traversal. It marks the current vertex as visited, prints its value, and then recursively
calls itself on each unvisited neighbor.
OUTPUT –

LEARNING –

DFS is a fundamental graph traversal algorithm used in many applications, such as


social network analysis, web crawlers, and network topology discovery. It's an
essential concept in computer science and software engineering. Understanding
DFS helps in solving complex problems, such as finding connected components,
detecting cycles, and performing topological sorting. Through learning and
implementing the Depth-First Search (DFS) algorithm, I've gained valuable insights
and skills in problem-solving strategies, graph theory fundamentals, programming
skills, and critical thinking and analysis. I've learned to break down complex
problems, use recursion, and think systematically to explore all possible solutions.
I've also developed a deeper understanding of graph representations, traversal
patterns, and properties. Additionally, I've improved my programming skills, including
implementing algorithms efficiently, writing clean code, and debugging and optimizing
for performance. Overall, mastering the DFS algorithm has enhanced my ability to
analyze problems, evaluate trade-offs, and develop a systematic approach to
problem-solving, preparing me to tackle more complex algorithms and real-world
challenges.
CONCLUSION –

In conclusion, the Depth-First Search (DFS) algorithm has been a valuable learning
experience, providing a solid foundation in problem-solving, graph theory, and
programming skills. By mastering DFS, I've developed a systematic approach to
tackling complex problems, improved my ability to analyze trade-offs, and enhanced
my programming skills. The skills and knowledge gained from learning DFS have
farreaching applications in computer science, enabling me to approach a wide range
of problems with confidence. As I continue to learn and grow, I'm excited to apply the
principles of DFS to more advanced algorithms and real-world challenges. With a
strong foundation in DFS, I'm well-equipped to tackle complex problems and make
meaningful contributions in the field of computer science.
Experiment - 5
AIM–
Given an undirected graph represented by an adjacency matrix. The graph has n
nodes, labeled from 1 to n. The task is to assign colors to each node in such a
way that no two adjacent nodes have the same color. The challenge is to solve
this problem using the minimum number of colors.

Theory–
Graph Coloring Theory
Given an undirected graph G = (V, E), where V is the set of vertices (nodes) and E
is the set of edges, the graph coloring problem involves assigning a color to each
vertex in V such that:
1. No two adjacent vertices (i.e., vertices connected by an edge) have the same
color.

2. The minimum number of colors is used.


Chromatic Number: The chromatic number of a graph G, denoted by χ(G), is the
minimum number of colors required to color the graph. A graph with chromatic
number k is said to be k-colorable.
Graph Coloring Algorithms: There are several algorithms to solve the graph
coloring problem, including:
1. Greedy Algorithm: Assign colors to vertices one by one, always choosing the
smallest available color.
2. Backtracking Algorithm: Try different color assignments and backtrack
when a conflict is found.
3. Constraint Programming: Formulate the problem as a constraint satisfaction
problem and solve it using constraint programming techniques.
Approximation Algorithms: To overcome NP-completeness, approximation
algorithms are used to find near-optimal solutions. These algorithms typically
have a guaranteed performance ratio, ensuring that the solution is within a
certain factor of the optimal solution.

Program -
OUTPUT–

LEARNING –
Familiarized with basic graph theory concepts, such as graphs, vertices, edges,
adjacency matrices,and graphrepresentation.Understoodthebasics ofalgorithm
design,including timeandspacecomplexity,andtrade-offsbetweendifferent
algorithms.Studiedthegraphcoloring problemdefinition,itsconstraints,andthegoal of
minimizingthenumber ofcolors used. Learnedaboutthechromatic number,Brooks' Theorem,
andtheNP-completenessofthegraphcoloring problem.Studiedthegreedy algorithm,
backtracking algorithm,andconstraint programming approaches tograph coloring. Analyze
their time and space complexities and trade-offs. Chosen a programming language (e.g.,
Python, C++, Java) and implement a graph coloring algorithm. Start with a simple greedy
algorithm and then move to more advanced
approaches. Learned about approximation algorithms for graph coloring, such as the linear
programming relaxation and semidefinite programming approaches. Learned how to
decompose graphs into smaller subgraphs to simplify the coloring process. Studied techniques
for coloring large graphs, including parallel and distributed algorithms.
Explored real-world applications of graph coloring, such as scheduling, resource
allocation, and network optimization.

Conclusion -
Graph coloring is a fundamental problem in computer science and graph theory, with numerous
applications in real-world problem-solving. A systematic approach to learning graph coloring
involves understanding the problem definition, graph theory, algorithmic thinking, and
implementation. Practice and experimentation are crucial in mastering graph coloring, and
utilizing resources such as textbooks, online courses,
and practice platforms can aid in the learning process. Approximation algorithms play a vital
role in solving large instances of the graph coloring problem, given its NPcompleteness.
Experiment 6
Aim– To implement pandas in python and create data frames
using the same

Program-

-
Description:
Pandas is a powerful Python library for data manipulation
and analysis. It offers:
1. Data Structures: The two main structures are Series
(1D) and Data Frame (2D), which allow you to work
with labelled data like Excel tables or SQL databases.

2. Data Handling: Pandas simplifies tasks like importing /


exporting data, cleaning missing values, filtering rows /
columns, and transforming datasets.

3. Aggregation and Grouping: It allows you to easily


group data by columns and apply functions like sum,
mean, or count to analyse large datasets.
Experiment 7
Aim– To perform basic Numpy operations.

Program -
Description –
Numpy is a powerful Python library for numerical computing,
offering a wide range of functions and tools for efficiently
handling and manipulating numerical data. It's a cornerstone of
many scientific computing and data analysis applications. Key
features and uses of Numpy:
Multidimensional Arrays: Numpy's primary data structure is the
ndarray, which can represent arrays of arbitrary dimensions.
This makes it ideal for handling matrices, vectors, and
higherdimensional data.
Efficient Operations: Numpy performs mathematical
operations on arrays much faster than Python's built-in lists,
thanks to its optimized C implementation. This is crucial for
large-scale numerical computations.

Broadcasting: Numpy's broadcasting mechanism allows for


automatic element-wise operations between arrays of different
shapes, simplifying calculations and reducing code complexity.

Linear Algebra: Numpy provides a rich set of functions for


linear algebra operations, including matrix multiplication,
inversion, eigenvalue decomposition, and more.

Random Number Generation: Numpy's random module offers a


variety of functions for generating random numbers from
different distributions, essential for simulations and statistical
analysis.

Fourier Transforms: Numpy's fft module implements efficient


algorithms for computing Fourier transforms, a fundamental
tool in signal processing and image analysis.

Integration with Other Libraries: Numpy seamlessly integrates


with other popular Python libraries like SciPy. Matplotlib, and
Pandas, making it a versatile tool for scientific computing and
data analysis workflows.
Experiment 8
Aim – Implementation of AO* Algorithm
Description - AO* Search Algorithm is a Path Finding Algorithm
and it is similar to A* star, other than AND is used between two
nodes along with OR. After getting shortest path it will return back
to root node and it will update it's heuristic value. It is similar to
Depth First Search(DFS). It will search shortest path using
heuristic value assigned to node and actual cost from
Source_node to Dest_node.

Program –
Output –

You might also like