AI Exp file (1)
AI Exp file (1)
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 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.
CONCLUSION –
CONCLUSION –
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 –
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.
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.
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.
Program –
Output –