DSL Lab Manual - AI&DS
DSL Lab Manual - AI&DS
Academic Year:2024-25
Semesters -I
Class: SE
INDEX
Department of AI-DS Engineering Class: S.E.
Sr. Date of Date of Page
Name of the Sign
No Experiment Conducti Checking No.
. on
Group-A
A-1
In second year computer engineering
1 class, group A student’s play cricket, group
B
students play badminton and group C
students play football.
Write a Python program using functions to
compute following: -
a) List of students who play both cricket
and badminton
b) List of students who play either cricket or
badminton but not both
c) Number of students who play neither
cricket nor badminton
d) Number of students who play cricket and
football but not badminton.
A-2
Write a Python program to store marks
2
scored in subject “Fundamental ofData
Structure” by N students in the class.
Write functions to compute following:
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent
for the test
Display mark with highest frequency
B-14
Write a pythonprogram to store first year
5 percentage of students in array. Write
function
for sorting array of floating point numbers
in ascending order using
a) Selection Sort
b) Bubble sort and display top five scores.
B-16
6 Write a Python program to store first year
percentage of students in array. Write
function for sorting array of floating-point
numbers in ascendingorder using quick sort
and display top five scores.
Group - C
C-19
Department of Computer Engineering has
student's club named 'Pinnacle Club'.
Students of second, third and final year of
department can be granted membership on
7
request. Similarly, one may cancel the
membership of club. First node is reserved
for president of club and last node is
reserved for secretary of club. Write C++
program to maintain club member ‘s
information using singly linked list. Store
student PRN and Name. Write functions to:
a) Add and delete the members as well as
president or even secretary. b) Compute
total number of members of club c) Display
members d) Two linked lists exists for two
divisions. Concatenate two lists.
CERTIFICATE
Date:
The laboratory practicals are to be submitted by student in the form of journal. Journal
consists of prologue, Certificate, table of contents, and handwritten write-up of each
practical (Title, Objectives, Problem Statement, Outcomes, software & Hardware
requirements, Date of Completion, Assessment grade/marks and assessor's sign, Theory-
Concept in brief, algorithm, flowchart, test cases, conclusion/analysis. Program codes with
sample output of all perform practical‟s are to be submitted as softcopy.
As a conscious effort and little contribution towards Green IT and environment awareness,
attaching printed papers as part of write-ups and program listing to journal may be avoided.
Use of DVD containing students’ programs maintained by lab In-charge is highly encouraged.
For referenceone or two journals may be maintained with program prints at Laboratory.
Continuous assessment of laboratory work is done based on overall performance and lab
practicals performance of student. Each lab practical assessment will assign grade/marks
based on parameters with appropriate weightage. Suggested parameters for overall
assessment as well as each labpractical assessment include- timely completion, performance,
innovation, efficient codes, punctuality and neatness.
Both internal and external examiners should jointly set problem statements. During practical
assessment, the expert evaluator should give the maximum weightage to the satisfactory
implementation of the problem statement. The supplementary and relevant questions may be
asked at the time of evaluation to test the students for advanced learning, understanding of
the fundamentals, effective and efficient implementation. So,
.
Data Structure and Lab (DSL)
encouraging efforts, transparent evaluation and fair approach of the evaluator will not
appropriate use of Hungarian notation, proper indentation and comments. Use of open source
software is to be encouraged.
In addition to these, instructor may assign one real life application in the form of a mini-
project based on the concepts learned. Instructor may also set one practical or mini-project
that is suitableto respective branch beyond the scope of syllabus.
Set of suggested practical list is provided in groups- A, B, C, D, and E. Each student must
perform at least 13 practicals as at least 3 from group A, 3 from group B, 2 from group C, 2
from group D and 3 from group E.
.
Experiment No-1
AIM:- To perform operations on set
TITLE:- In second year computer engineering class, group A student?s play cricket, Group
B students play badminton and group C students play football. Write a Python program
using functions to compute following: -
a) List of students who play both cricket and badminton
b) List of students who play either cricket or badminton but not both
c) Number of students who play neither cricket nor badminton
d) Number of students who play cricket and football but not badminton.
OBJECTIVES:-
1) To know the basics of set.
2) To perform operation on array.
3) To implement set operation using array
THEORY:-
Set Theory:
No restriction is placed on the nature of the objects in a set. They can be anything: points,
lines, numbers, people, countries, etc. Thus the mathematical meaning of the word set is the
same as the regular, nontechnical meaning of the word.
Examples of sets.
- All points in a given line segment
- Lines through a given point in space
- The set of all rational numbers
- Solutions of the equation 3x2 + 2y2 - 1 = 0
- Citizens of England
- Rivers of Mexico
Union of sets: The union of two sets A and B is the set consisting of all elements in A plus all
elements in B and is denoted by A∪B or A + B
Example: The set of all even integers could be considered a subset of a universal set
consisting of all the integers. Or they could be considered a subset of a universal set
consisting of all the rational numbers. Or of all the real numbers.
ALGORITHM:-
1) Start
2) Declare variable and string
3) Accept input from user
4) Define all functions and perform all operations
5) Display the output
6) Stop
CONCLUSION:-
Experiment No-2
Practical Title: Write a python program to store marks for N students.
Aim: - Write a Python program to store marks scored in subject “Fundamental of Data
Structure” by N students in the class. Write functions to compute following:
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent for the test
d) Display mark with highest frequency
Prerequisite:
• Python Programming
Objectives:
To understand the use functions for N students, record.
Declaring Arrays
To declare an array in C, a programmer specifies the type of the elements and the number of
elements required by an array as follows −
type arrayName [ arraySize ];
This is called a single-dimensional array. The arraySize must be an integer constant greater than
zero and type can be any valid C data type. For example, to declare a 10-element array called
balance of type double, use this statement −
double balance[10];
Data Structure and Lab SE Computer
(DSL) Engineering
Initializing Arrays
You can initialize an array in C either one by one or using a single statement as follows −
double balance[5] = {1000.0, 2.0, 3.4, 7.0, 50.0};
Functions Used:
Write algorithm/pseudo code for each function.
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent for the test
d) Display mark with highest frequency
Algorithm:
WRITE ALGO.
Flowchart:
Here, draws flowchart of above algorithm.
Conclusion:
By this way, we can store the marks of N students sucessfully.
Questions:
1. Basics of python Programming.
2. What are functions?
3. What are the features of python Programming?
4. What are array?
.
Experiment No-3
Pre-requisite:
• Knowledge of representing matrix in Python
• Knowledge of different operations that can be performed on matrix
Objectives:
• Compute the transpose of matrix
• Perform addition , subtraction and multiplication of two matrices.
Input:
Number of rows and columns of two matrices
Elements of both the matrices
Outcome:
• Transpose of a matrix
Theory:
• Number of rows and columns of two matrices
• Elements of both the matrices
• Transpose of a matrix
• Result of addition , subtraction and multiplication of both matrices.
2-dimension array –
1. Start
2. Input number of rows and columns of first matrix.
3. Input elements of first matrix.
4. Input number of rows and columns of second matrix.
5. Input elements of Second matrix.
6. Function to transpose first matrix i.e. the element at row r column c in the original is
placed at row c column r of the transpose.
7. Fuction to add, subtract and multiply two matrices.
Flowchart :
Draw flowchart for above algorithm
Conclusion:
By this way, we can perform various operations on matrix successfully.
Questions:
1.What is upper triangular matrix and lower triangular matrix?
2. How to find transpose of a matrix.
3. Different operations on matrix.
Data Structure and Lab (DSL) SE Computer Engineering
Practical
No:04(B)
Aim: Write a python program to maintain club members, sort on roll numbers in
ascending
order. Write function “Ternary_Search” to search whether particular student is
member
of club or not. Ternary search is modified binary search that divides array into 3
halves
instead of two.
Pre-requisite:
Objective:
To Search array of floating point numbers in ascending order using
A)Ternary Search
Input:
Size of array Elements of array
Theory :
- Write short theory of Seraching Techniques &it’s Type with its
advantages and disadvantages.
- Explain Ternary Search with example
Algorithm:
Steps to perform Ternary Search:
1. First, we compare the key with the element at mid1. If found equal, we
return mid1.
2. If not, then we compare the key with the element at mid2. If found equal, we
return mid2.
3. If not, then we check whether the key is less than the element at mid1. If yes,
then recur to the first part.
4. If not, then we check whether the key is greater than the element at mid2. If
yes, then recur to the third part.
5. If not, then we recur to the second (middle) part.
Data Structure and Lab (DSL) SE Computer Engineering
Flowchart :
Conclusion:
By this way, we can perform searching of an array using Ternary Search technique.
Practical No:05(B)
Practical Title: Sorting of an array using selection and bubble sort.
Aim: Write a Python program to store first year percentage of students in array. Write function for
sorting array of floating point numbers in ascending order using
a) Selection Sort
Pre-requisite:
Objective:
To sort array of floating point numbers in ascending order using
a) Selection Sort b) Bubble sort and display top five scores.
Input:
Size of array Elements of array
Theory :
- Write short theory of sorting with its advantages and disadvantages.
- Explain selection and bubble sort with example
Algorithm:
def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
alist = [54,26,93,17,77,31,44,55,20]
bubbleSort(alist)
print(alist)
def selectionSort(alist):
for fillslot in range(len(alist)-1,0,-1):
positionOfMax=0
for location in range(1,fillslot+1):
Data Structure and Lab (DSL) SE Computer Engineering
if alist[location]>alist[positionOfMax]:
positionOfMax = location
temp = alist[fillslot]
alist[fillslot] = alist[positionOfMax]
alist[positionOfMax] = temp
alist = [54,26,93,17,77,31,44,55,20]
selectionSort(alist)
print(alist)
Flowchart :
Conclusion:
By this way, we can perform sorting of an array using selection and bubble sort.
Practical
No:05(B)
Practical Title: Sorting of an array using selection and bubble sort.
Aim: Write a Python program to store first year percentage of students in array. Write
function for sorting array of floating point numbers in ascending orderusing
a) Selection Sort
b)Bubble sort and display top five scores.of club.
Pre-requisite:
Objective:
To sort array of floating point numbers in ascending order using
a) Selection Sort b) Bubble sort and display top five scores.
Input:
Size of array Elements of array
Theory :
- Write short theory of sorting with its advantages and disadvantages.
- Explain selection and bubble sort with example
Algorithm:
def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-
1): for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
Data Structure and Lab (DSL)
alist = [54,26,93,17,77,31,44,55,20]
bubbleSort(alist)
print(alist)
def selectionSort(alist):
for fillslot in range(len(alist)-1,0,-1):
positionOfMax=0
for location in range(1,fillslot+1)
temp = alist[fillslot]
alist[fillslot] = alist[positionOfMax]
alist[positionOfMax] = temp
alist = [54,26,93,17,77,31,44,55,20]
selectionSort(alist) print(alist)
Data Structure and Lab (DSL)
SE Computer Engineering
Flowchart :
Conclusion:
By this way, we can perform sorting of an array using selection and bubble sort.
Question Bank:
Practical
No:06(B)
Practical Title: Sorting array of floating point numbers in ascending order using quick
sort.
Aim: Write a Python program to store first year percentage of students in array. Write
function for sorting array of floating point numbers in ascending order using quick sort and
display top five scores.
Pre-requisite:
Objective:
• To sort array using quick sort
Input:
Size of array
First year percentage of students.
Outcome:
• To sort array using quick sort
• To display top five scores.
Theory :
- Explain concept of Quick sort in details.
- Advantages and disadvantages
- Example of quick sort.
- Time complexity.
Data Structure and Lab (DSL)
SE Computer Engineering
Algorithm:
def quickSort(alist):
quickSortHelper(alist,0,len(alist)-1)
def quickSortHelper(alist,first,last):
if first<last:
splitpoint = partition(alist,first,last)
quickSortHelper(alist,first,splitpoint-1)
quickSortHelper(alist,splitpoint+1,las
t)
def partition(alist,first,last):
pivotvalue = alist[first]
leftmark = first+1
rightmark = last
done = False
while not done:
Flowchart :
Conclusion:
By this way, we can perform sorting array of floating point numbers in ascending order
using quick sort
Question Bank:
1. Explain the sorting?
2. What are the different types of sorts in data structures?
3. Define the quick sort?
5. How many passes are required in
quick sort? 6.What is the time complexity of
quick sort
GROUP - C
Data Structure and Lab (DSL)
Practical No : 07 (C)
Assignmet Title: Write C++ program to maintain club member‘s information using
singly linked list.
Aim: Department of Computer Engineering has student's 1/8 club named 'Pinnacle Club'.
Students of Second, third and final year of department can be granted membership on
request. Similarly one may cancel the membership of club. First node is reserved for
president of club and last node is reserved for secretary of club. Write C++ program to
maintain club member‘s information using singly linked list. Store student PRN and Name.
Write functions to
a) Add and delete the members as well as president or even secretary.
b) Compute total number of members of club
c) Display members
d) Display list in reverse order using recursion
e) Two linked lists exists for two divisions. Concatenate two lists
Theory:
Linked List : (write linked list definition and sinly linked list theory)
- Definition :
- Types of linked list
- Singly linked list (definition, concepts, advantages, disadvantages)
- Singly linked list as an ADT (Write pseudo code for each ADT)
- Algorithm
- Flowchart :
(draw your own flowchart for your algorithms)
Conclusion:
By this way, we can maintain club member‘s information using singly linked list.
.
Data Structure and Lab (DSL)
12. What will you prefer to use a singly or a doubly linked lists for traversing through
a list of elements?
.
Data Structure and Lab (DSL)
Practical Title: The ticket booking system of Cinemax theater has to be implemented using
C++ program. There are 10 rows and 7 seats in each row. Doubly circular linked
list has to be maintained to keep track of free seats at rows. Assume some
random booking to start with. Use array to store pointers (Head pointer) to each
row. On demand
a) The list of available seats is to be displayed
b) The seats are to be booked
c) The booking can be cancelled.
Pre-requisite:
Objective:
Input:
Row no and seat no to book seat
Outcome:
• Diplay available seats to book movie ticket.
• Display status of Booked seat/ cancel seat.
.
Data Structure and Lab (DSL)
Theory :
Circular Doubly linked list : (write CDLL theory in details i.e. definition,
concepts, advantages, disadvantages.)
- Doubly Circular linked list as an ADT : (write pseudo code for each
operation)
- Algorithms :
- Flowchart :
Conclusion:
By this way, we can book or cancel movie ticket using doubly Circular linked lists.
.
GROUP - D
Data Structure and Lab (DSL)
Practical No:09(D)
Aim:A palindrome is a string of character that‘s the same forward and backward. Typically,
punctuation, capitalization, and spaces are ignored. For example, “Poor Dan is in a droop”
is a palindrome, as can be seen by examining the characters “poor danisina droop” and
observing that they are the same forward and backward. One way to check for a
palindrome is to reverse the characters in the string and then compare with them the
original-in a palindrome, the sequence will be identical. Write C++ program with
functions
a) To print original string followed by reversed string using stack
b) To check whether given string is palindrome or not
Pre-requisite:
Objective:
a) To print original string followed by reversed string using stack
b) To check whether given string is palindrome or not
Input:
“Poor Dan is in a droop”
is a palindrome, as can be seen by examining the characters
“poor danisina droop” and observing that they are the same forward and backward.
Outcome:
To check whether given string is palindrome or not
.
Data Structure and Lab (DSL)
Theory :
- Write short theory of Palindrome string
-How do you solve a palindrome string problem?
-How do you find the palindrome of a string?
-How do you identify a palindrome?
Algorithms :
Write your own algorithms
Flowchart :
Draw flowchart for above algorithms.
Conclusion:
By this way, we can check To check whether given string is palindrome or not
.
Data Structure and Lab (DSL)
Practical No:10(D)
Practical Title: Write C++ program to check well form of parenthesis using stack.
Aim: In any language program mostly syntax error occurs due to unbalancing delimiter
such as (),
{},[]. Write C++ program using stack to check whether given expression is well
parenthesized or not.
Pre-requisite:
• Basics of stack.
• Different operations that can be performed on stack
Objective:
• To check whether the given expression is well parenthesized or not.
Input:
Expression using {},(),[].
Outcome:
• Result of checking well formedness of parenthesis.
Theory :
- Write short theory of stack.
- Write concept of well form parenthesis.
- Example of well form parenthesis.
Algorithms :
Write your own algorithms
Flowchart :
Draw flowchart for above algorithms.
Conclusion:
By this way, we can check well form of parenthesis using stack.
Question Bank:
1. What is Stack?
2. Which are the different operations that can be performed on stack?
3. Explain PUSH, POP operations on stack
4. What are the applications of stack?
.
GROUP - E
Practical No:11 (E)
Pre-requisite:
• Basics of Queue
• Different operations that can be performed on queue
Objective:
• To perform addition and deletion operations on queue.
Input:
Size of queue
Elements in quque
Outcome:
• Result of addition of job operation on queue.
• Result of deletion of job operation on queue.
Theory :
Step 1: Include all the header files which are used in the program and define a constant
'SIZE' with specific value.
Step 2: Declare all the user defined functions which are used in queue implementation.
Step 3: Create a one dimensional array with above defined SIZE (int queue[SIZE])
Step 4: Define two integer variables 'front' and 'rear' and initialize both with '-1'. (int front = -
1, rear
= -1)
Step 5: Then implement main method by displaying menu of operations list and make
suitable function calls to perform operation selected by the user on queue.
Flowchart:
Draw flowchart for above algorithms
Conclusion:
By this way, we can perform different operations on queue
Question Bank:
1. What is Queue?
2. What are the different operations that can be performed on queue?
3. Explain all the operations on queue
4. Which are different types of queues , Explain.
Practical No:12(E)
Practical Title: Perform operations on Double ended queue.
Aim: A double-ended queue(deque) is a linear list in which additions and deletions may be
made at either end. Obtain a data representation mapping a deque into a one-dimensional
array. Write C++ program to simulate deque with functions to add and delete elements
from either end of the deque.
Pre-requisite:
• Knowledge of Queue
• Types of queue
• Knowledge of double ended queue and different operations that can be performed on it
Objective:
• To simulate deque with functions to add and delete elements from either end of the
deque.
Input:
Size of array Elements
in the queue
Outcome:
• Result of deque with functions to add and delete elements from either end of the
deque.
Theory :
Double-Ended Queue
A double-ended queue is an abstract data type similar to an simple queue, it allows you to
insert and delete from both sides means items can be added or deleted from the front or
rear end.
if rear=0
rear=1; if
front=0
front=1;
Step-3: return
void add_item_rear()
{
int num;
printf("\n Enter Item to insert : ");
scanf("%d",&num);
if(rear==MAX)
{
printf("\n Queue is Overflow");
return;
}
else
{
rear++;
q[rear]=num;
if(rear==0)
rear=1;
if(front==0)
front=1;
}
}
void add_item_front()
{
int num;
printf("\n Enter item to insert:");
scanf("%d",&num);
if(front<=1)
{
printf("\n Cannot add item at front end");
return;
}
else
{
front--;
q[front]=num;
}
}
void delete_item_front()
{
int num;
if(front==0)
{
printf("\n Queue is Underflow\n");
return;
}
else
{
num=q[front];
printf("\n Deleted item is %d\n",num);
if(front==rear)
{
front=0;
rear=0;
}
else
{
front++;
}
}
}
void delete_item_rear()
{
int num;
if(rear==0)
{
printf("\n Cannot delete item at rear
end\n"); return;
}
else
{
num=q[rear];
if(front==rear)
{
front=0;
rear=0;
}
else
{
rear--;
printf("\n Deleted item is %d\n",num);
}
}
}
Algorithms :
Write your own algorithms
Flowchart :
Draw flowchart for above algorithms
Conclusion:
By this way, we can perform operations on double ended queue
Question Bank:
1. What is queue?
2. Types of queue
3. What is double ended queue?
4. How to insert the new node in Doubly Link List?
5. How to delete the node from front of Doubly Link List ?
6. How to delete the node from end of Doubly Link List ?
7. How to delete the node in between of Doubly Link List
Practical No:13(E)
Practical Title: Perform operations on Circular queue.
Aim: Pizza parlor accepting maximum M orders. Orders are served in first come first
served basis. Order once placed cannot be cancelled. Write C++ program to
simulate the system using circular queue using array
Pre-requisite:
Objective:
• To simulate circular queue with functions to add and delete elements from
Circular queue.
Input:
Accept order
Elements in the queue
Outcome:
• Result of Circular queue with functions to accept or cancel Pizza order.
Theory :
Now consider the following situation after deleting three elements from the queue...
This situation also says that Queue is Full and we can’t insert the new element because, 'rear' is still at
last position. In above situation, even though we have empty positions in the queue we can’t make use
of them to insert new element. This is the major problem in normal queue data structure. To overcome
this problem we use circular queue data structure.
• What is a Circular Queue?
A Circular Queue can be defined as follows...
Circular Queue is a linear data structure in which the operations are performed based on FIFO (First In
First Out) principle and the last position is connected back to the first position to make a circle.
To implement a circular queue data structure using array, we first perform the following steps
before we implement actual operations.
Step 1: Include all the header files which are used in the program and define a constant 'SIZE' with
specific value.
Step 2: Declare all user defined functions used in circular queue implementation.
Step 3: Create a one dimensional array with above defined SIZE (int cQueue[SIZE])
Step 4: Define two integer variables 'front' and 'rear' and initialize both with '-1'. (int front = -1, rear
= -1) Step 5: Implement main method by displaying menu of operations list and make suitable function
calls to perform operation selected by the user on circular queue.
Step 1: Check whether queue is FULL. ((rear == SIZE-1 && front == 0) || (front == rear+1))
Step 2: If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and terminate the
function.
Step 3: If it is NOT FULL, then check rear == SIZE - 1 && front != 0 if it is TRUE, then set rear = -1.
Step 4: Increment rear value by one (rear++), set queue[rear] = value and check 'front == -1' if it
is TRUE, then set front = 0.
Algorithms :
Write your own algorithms
Flowchart :
Draw flowchart for above algorithms
Conclusion:
Hence we have learned how to implement Circular Queue and perform various operations on it.
Question Bank: