Shri Vaishnav Vidyapeeth Vishwavidyalaya
Shri Vaishnav Vidyapeeth Vishwavidyalaya
January-July 2023
INDEX
PRACTICAL 01
operators, loops).
THEORY:
This program begins with a simple "Hello World" statement printed to the console.
The next section demonstrates how to create a function in Python. The add_numbers function
takes two arguments, a and b, and returns their sum. The function is then called with a equal
to 2 and b equal to 3, and the result is printed to the console.
The next section demonstrates different data types in Python, including integers, floats,
strings, and booleans.
The next section demonstrates different operators in Python, including addition, subtraction,
multiplication, division, modulus, and exponentiation.
Finally, the program demonstrates a simple for loop that prints the numbers from 0 to 9 to the
console.
CODE:
OUTPUT:
PRACTICAL 0
2 AIM:
WRITE A PROGRAM FOR ARRAY AND LIST.
THEORY:
Array in Python
An array is also a linear data structure that stores the data. It is also ordered,
mutable, and enclosed in square brackets. It can store the non-unique items. But
there are restrictions to store the different data type values.
To work with the Array in Python, we need to import either an array module or
a Numpy.
Import array as ar
Import numphy as np
List in Python:
A list in Python is used to store the sequence of various types of data. A list can
be defined as a collection of values or items of different types. Python lists are
mutable type which implies that we may modify its element after it has been
formed. The items in the list are separated with the comma (,) and enclosed with
the square brackets [].
Although Python has six data types that may hold sequences, the list is the most
popular and dependable form. The collection of data is stored in a list, a
sequence data type. Similar sequence data formats are Tuples and String.
Python lists are identical to dynamically scaled arrays that are specified in other
languages, such as Java's ArrayList and C++'s vector. A list is a group of items
that are denoted by the symbol [] and subdivided by commas.
Example:
print(thislist)
PRACTICAL 0
CODE:
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
OUTPUT:
THEORY:
It is a recursive algorithm to search all the vertices of a tree data structure or a graph.
The depth-first search (DFS) algorithm starts with the initial node of graph G and goes
deeper until we find the goal node or the node with no children.
Because of the recursive nature, stack data structure can be used to implement the
DFS algorithm. The process of implementing the DFS is similar to the BFS algorithm.
The step by step process to implement the DFS traversal is given as follows –
First, create a stack with the total number of vertices in the graph.
• Now, choose any vertex as the starting point of traversal, and push that vertex
into the stack.
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
PRACTICAL 0
• After that, push a non-visited vertex (adjacent to the vertex on the top of the
stack) to the top of the stack.
• Now, repeat steps 3 and 4 until no vertices are left to visit from the vertex on
the stack's top.
• If no vertex is left, go back and pop a vertex from the stack.
• Repeat steps 2, 3, and 4 until the stack is empty.
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
PRACTICAL 0
THEORY:
Breadth-first search is a graph traversal algorithm that starts traversing the graph
from the root node and explores all the neighboring nodes. Then, it selects the
nearest node and explores all the unexplored nodes. While using BFS for
traversal, any node in the graph can be considered as the root node.
There are many ways to traverse the graph, but among them, BFS is the most
commonly used approach. It is a recursive algorithm to search all the vertices of
a tree or graph data structure. BFS puts every vertex of the graph into two
categories - visited and non-visited. It selects a single node in a graph and, after
that, visits all the nodes adjacent to the selected node.
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
PRACTICAL 0
ANKIT PATIDAR
20100BTCSBS07457
ARTIFICIAL INTELLIGENCE BTCSDS311
PRACTICAL 0
THEORY:
Problem Statement
Given two water jugs with capacities X and Y litres. Initially, both the jugs are
empty. Also given that there is an infinite amount of water available. The jugs do
not have markings to measure smaller quantities.
One can perform the following operations on the jug:
• Pour water from one jug to the other until one of the jugs is either empty or
full, (X, Y) -> (X – d, Y + d)
• Empty any of the jugs
Example:
Input: X = 4, Y = 3, Z = 2
Explanation:
PRACTICAL 0 AIM:
WRITE A
THEROY:
Tower of Hanoi is a mathematical puzzle where we have three rods (A, B, and C) and N
disks. Initially, all the disks are stacked in decreasing value of diameter i.e., the smallest
disk is placed on the top and they are on rod A. The objective of the puzzle is to move the
entire stack to another rod (here considered C), obeying the following simple rules:
PRACTICAL 0 AIM:
WRITE A
THEROY:
PRACTICAL 0 AIM:
WRITE A
THEROY:
The constant sum in every row, column and diagonal are called the magic constant
or magic sum, M. The magic constant of a normal magic square depends only on n
and has the following value:
M = n(n2+1)/2
PRACTICAL 0 AIM:
WRITE A
THEROY:
Explanation: play_game() is the main function, which performs the following tasks :
• Evaluate the board after each move to check whether a row or column or
diagonal has the same player number. If so, displays the winner’s name.
If after 9 moves, there is no winner then displays -1.
CODE:
OUTPUT: