0% found this document useful (0 votes)
43 views43 pages

Ds Adip

The document outlines a laboratory assignment for the Data Structures course at Acropolis Institute of Technology and Research, focusing on practical applications of data structures. It includes objectives, course syllabus, general instructions, and specific programming tasks related to data structures such as arrays, stacks, queues, trees, and graphs. Additionally, it provides evaluation criteria and sample programs demonstrating insertion, deletion, and stack operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views43 pages

Ds Adip

The document outlines a laboratory assignment for the Data Structures course at Acropolis Institute of Technology and Research, focusing on practical applications of data structures. It includes objectives, course syllabus, general instructions, and specific programming tasks related to data structures such as arrays, stacks, queues, trees, and graphs. Additionally, it provides evaluation criteria and sample programs demonstrating insertion, deletion, and stack operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

2024-25

Acropolis Institute of
Technology and
Research, Indore
Department of CSE
Submitted To: Dr. Mayur Rathi (Artificial Intelligence & Machine
Learning)

Data Structures (AL303)

Submitted By:
Name of Student
Enrollment No. : 0827
Class/Year/Sem : ALS-1/2nd / 3rd

[LAB ASSIGNMENT DATA STRUCTURES (AL-


303)]
The Objective of this laboratory work is to strengthen the ability of the students to identify
and apply the suitable data structure for the given real world problem. It enables them to gain
knowledge in practical applications of data structures.
ACROPOLIS INSTITUTE OF TECHNOLOGY & RESEARCH,
INDORE

Department of CSE (Artificial Intelligence & Machine Learning)

CERTIFICATE

This is to certify that the experimental work entered in this journal as per

the B. TECH. II year syllabus prescribed by the RGPV was done by Mr./

Ms. …………………………………[Link] II year III semester in the

Data Structures Laboratory of this institute during the academic year

2024- 2025.

Signature of the Faculty


About the Laboratory

In this lab, students will be able to learn and practice basic data structures programming. Students
can expand their skill set by practical learning on various data structures and to understand the
processing of different algorithm for problem-solving. This lab complements the data structures and
computer algorithms courses. Data Structures provides the requisite environment for design and
analysis of algorithms for solving complex problems in the field of computer science. Students gain
practical knowledge by writing and executing programs in C/C++/JAVA/Python using various data
structures and implementing algorithm principles. The latest platforms compilers are provided to the
students to run their programs.
GENERAL INSTRUCTIONS FOR LABORATORY CLASSES

 DO’S

 Without Prior permission do not enter into the Laboratory.

 While entering into the LAB students should wear their ID cards.

 The Students should come with proper uniform.

 Students should sign in the LOGIN REGISTER before entering into the
laboratory.

 Students should come with observation and record note book to the laboratory.

 Students should maintain silence inside the laboratory.

 After completing the laboratory exercise, make sure to shutdown the system
properly.

 DONT’S

 Students bringing the bags inside the laboratory.

 Students using the computers in an improper way.

 Students scribbling on the desk and mishandling the chairs.

 Students using mobile phones inside the laboratory.

 Students making noise inside the laboratory.


SYLLABUS
Course: AL303 (Data Structures)
Branch/Year/Sem: Artificial Intelligence & Machine Learning / II / III

Module1: Introduction to Data Structure: Concepts of Data and Information,


Classification of Data structures, Abstract Data Types, Implementation aspects: Memory
representation. Data structures operations and its cost estimation. Introduction to linear
data structures- Arrays, Linked List: Representation of linked list in memory, different
implementation of linked list. Circular linked list, doubly linked list, etc. Application of
linked list: polynomial manipulation using linked list, etc..

Module2: Stacks and Queue: Stacks as ADT, Different implementation of stack,


multiple stacks. Application of Stack: Conversion of infix to postfix notation using
stack, evaluation of postfix expression, Recursion. Queues: Queues as ADT, Different
implementation of queue, Circular queue, Concept of Dqueue and Priority Queue, Queue
simulation, Application of queues.

Module3: Tree: Definitions - Height, depth, order, degree etc. Binary Search Tree -
Operations, Traversal, Search. AVL Tree, Heap, Applications and comparison of various
types of tree; Introduction to forest, multi-way Tree, B tree, B+ tree, B* tree and red-
black tree.

Module4: Graphs: Introduction, Classification of graph: Directed and Undirected


graphs, etc, Representation, Graph Traversal: Depth First Search (DFS), Breadth First
Search (BFS), Graph algorithm: Minimum Spanning Tree (MST)-Kruskal, Prim’s
algorithms. Dijkstra’s shortest path algorithm; Comparison between different graph
algorithms. Application of graphs.

Module5: Sorting: Introduction, Sort methods like: Bubble Sort, Quick sort. Selection
sort, Heap sort, Insertion sort, Shell sort, Merge sort and Radix sort; comparison of
various sorting techniques. Searching: Basic Search Techniques: Sequential search,
Binary search, Comparison of search methods. Hashing & Indexing. Case Study:
Application of various data structures in operating system, DBMS etc.
HARDWARE AND SOFTWARE REQUIREMENTS:

S. Name of Item Specification


No.
1 Computer System Hard Disk min 5 GB
RAM: 4 GB / 8 GB
Processor: Intel i3 or above

S. Name of Item Specification


No.
1 Operating system Window XP or 2000
Editor Python3.7 IDLE or Google Colab or
Spyder(Anaconda) , Turbo C/C++
RATIONALE:
The purpose of this subject is to cover the concepts of Data Structure in terms of Theory
and Implementation .The syllabus provides all the essential concepts of Data Structures.

PREREQUISITE:-

Experience with a high level language (C/C++, Java, Python) is suggested. Prior
knowledge of a Object-Oriented concepts is helpful but not mandatory.

COURSE OBJECTIVES AND OUTCOMES

 Course Objectives

1. To write and execute programs in any high level language to solve problems using
data structures such as arrays, linked lists.
2. To write and execute programs in any high level language to solve problems using
data structures such as stacks, queues.
3. To write and execute programs in C++ to solve problems using data structures
such as trees, graphs, hash tables and search trees.  To write and execute write
programs in C++ to implement various sorting and searching methods..

 Course Outcomes

At the end of the course student will be able to:

1. List different types of data structures


2. Illustrate the concepts of stack and queue
3. Describe the concepts of various tree
4. Discuss the concepts of Graph
5. Demonstrate various algorithms of sorting

.
Index
Date of Page Date of Grade & Sign
[Link] Exp. Name of the Experiment No. Submission of the Faculty

1 Program for insertion and deletion in array at


different positions. (CO 1)

2 Program to perform Insertion and deletion operation


in linked list. (CO 1)

3 Program to perform Push, Pop & top operations in


stack. (CO 2)

4 Program to perform Insertion and deletion operation


in queue. (CO 2)

5 Program to create a tree. (CO 3)

6 Program to implement Selection Sort. (CO 5)

7 Program to implement Insertion Sort. (CO 5)

8 Program to implement Quick Sort. (CO 5)

9 Program to implement Merge Sort. (CO 5)

10 Program to implement Binary Search. (CO 5)


Program Outcome (PO)

The engineering graduate of this institute will demonstrate:


a) Apply knowledge of mathematics, science, computing and engineering fundamentals to computer
science engineering problems.
b) Able to identify, formulate, and demonstrate with excellent programming, and problem solving skills.
c) Design solutions for engineering problems including design of experiment and processes to meet
desired needs within reasonable constraints of manufacturability, sustainability, ecological,
intellectual and health and safety considerations.
d) Propose and develop effective investigational solution of complex problems using research
methodology; including design of experiment, analysis and interpretation of data, and combination of
information to provide suitable conclusion. synthesis
e) Ability to create, select and use the modern techniques and various tools to solve engineering
problems and to evaluate solutions with an understanding of the limitations.
f) Ability to acquire knowledge of contemporary issues to assess societal, health and safety, legal and
cultural issues.
g) Ability to evaluate the impact of engineering solutions on individual as well as organization in a
societal and environmental context, and recognize sustainable development, and will be aware of
emerging technologies and current professional issues.
h) Capability to possess leadership and managerial skills, and understand and commit to professional
ethics and responsibilities.
i) Ability to demonstrate the team work and function effectively as an individual, with an ability to
design, develop, test and debug the project, and will be able to work with a multi-disciplinary team.
j) Ability to communicate effectively on engineering problems with the community, such as being able
to write effective reports and design documentation.
k) Flexibility to feel the recognition of the need for, and have the ability to engage in independent and
life- long learning by professional development and quality enhancement programs in context of
technological change.
l) A practice of engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and entrepreneurship.
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Program for insertion and deletion in array at
Lab: Data Structure (AL303) different positions.

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

1 Title
Program for insertion and deletion in array at different positions.
2 Neatly Drawn and labeled experimental setup

3 Theoretical solution of the instant problem


In this problem, we are dealing with insertion and deletion operations at any position within an array. Arrays
in C++ are fixed-size data structures, but these operations require careful management of the array’s size.

3.1 Algorithm
Insertion at a Specific Position:
1. Shift all elements from the position onwards by one index to the right.
2. Insert the new element at the specified position.
Deletion at a Specific Position:
1. Shift all elements from the position onwards by one index to the left.
2. The element at the specified position is effectively removed, and the size of the array reduces.

3.2 Program
#include <iostream>
using namespace std;

void displayArray(int arr[], int size) {


for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}

void insertAtPosition(int arr[], int& size, int element, int position) {

if (position < 0 || position > size) {


cout << "Invalid position for insertion!" << endl;
return;
}

for (int i = size; i > position; i--) {


arr[i] = arr[i - 1];
}

arr[position] = element;
size++;
cout << "Element inserted successfully!" << endl;
}

Page 10
void deleteAtPosition(int arr[], int& size, int position) {

if (position < 0 || position >= size) {


cout << "Invalid position for deletion!" << endl;
return;
}

for (int i = position; i < size - 1; i++) {


arr[i] = arr[i + 1];
}

size--;
cout << "Element deleted successfully!" << endl;
}

int main() {
int arr[10];
int size = 3;
arr[0] = 10; arr[1] = 20; arr[2] = 30;

cout << "Initial array: ";


displayArray(arr, size);

insertAtPosition(arr, size, 15, 1);


displayArray(arr, size);

insertAtPosition(arr, size, 5, 0);


displayArray(arr, size);

deleteAtPosition(arr, size, 2);


displayArray(arr, size);

deleteAtPosition(arr, size, 0);


displayArray(arr, size);

Page 11
return 0;
}

4 Tabulation Sheet

INPUT OUTPUT
5 Results
o Initial array: 10 20 30
o Element inserted successfully!
o 10 15 20 30
o Element inserted successfully!
o 5 10 15 20 30
o Element deleted successfully!
o 5 10 20 30
o Element deleted successfully!
o 10 20 30

 Initial array: 10 20 30
 Insert 15: 10 15 20 30
 Insert 5: 5 10 15 20 30
 Delete 15: 5 10 20 30
 Delete 5: 10 20 30
Final array: 10 20 30

Page 12
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Implementation of Stack Operations (Push, Pop,
and Top) in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Implementation of Stack Operations (Push, Pop, and Top) in C++
Neatly Drawn and labeled experimental setup

Page 13
Theoretical solution of the instant problem
A stack is a linear data structure that follows the LIFO (Last In First Out) principle. It supports the following
operations:
[Link]: Adds an element to the top of the stack.
[Link]: Removes the topmost element from the stack.
[Link]: Retrieves the element at the top of the stack without removing it.
.

Algorithm
[Link] an empty stack.
[Link] Push operation:
•Add the element to the top of the stack.
[Link] Pop operation:
•Remove the element from the top of the stack.
[Link] Top operation:
•Return the element at the top of the stack without removing it.

Program
#include <iostream>
using namespace std;

class Stack {
private:
int arr[100]; // Fixed-size array for simplicity

Page 14
int top;

public:
Stack() {
top = -1; // Initialize stack as empty
}

void pushElement(int x) {
if (top == 99) {
cout << "Stack Overflow!" << endl;
} else {
arr[++top] = x;
}
}

void popElement() {
if (top == -1) {
cout << "Stack is empty!" << endl;
} else {
--top;
}
}

void topElement() {
if (top == -1) {
cout << "Stack is empty!" << endl;
} else {
cout << "Top element: " << arr[top] << endl;
}
}

bool isEmpty() {
return top == -1;
}
};

int main() {

Page 15
Stack stack;
int choice, value;

while (true) {
cout << "1. Push\n2. Pop\n3. Top\n4. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice) {
case 1:
cout << "Enter value to push: ";
cin >> value;
[Link](value);
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
exit(0);
default:
cout << "Invalid choice!" << endl;
}
}

return 0;
}

Tabulation Sheet

Page 16
INPUT OUTPUT
1. Push Top element: 24
2. Pop
3. Top
4. Exit

Enter your choice: 1


Enter value to push: 12

1. Push
2. Pop
3. Top
4. Exit

Enter your choice: 1


Enter value to push: 24

1. Push
2. Pop
3. Top
4. Exit
Enter your choice: 3

Results
•Push operation adds elements to the stack successfully.
•Pop operation removes the top element from the stack and displays the new top.
•Top operation correctly displays the top element of the stack without removing it.
•The program handles empty stack situations and invalid inputs.

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Insertion and Deletion Operations in Queue
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment

Page 17
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Insertion and Deletion Operations in Queue
Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


A queue is a linear data structure that follows the FIFO (First In, First Out) principle. The two main operations in a
queue are insertion (enqueue) and deletion (dequeue). Insertion adds elements to the rear of the queue,
while deletion removes elements from the front of the queue.

Algorithm
•Insertion (Enqueue) Operation:
[Link] if there is space available in the queue.
[Link] space is available, insert the element at the rear end.

Page 18
[Link] the rear pointer.
•Deletion (Dequeue) Operation:
[Link] if the queue is empty.
[Link] not, remove the element from the front of the queue.
[Link] the front pointer.

Program
#include<iostream>
using namespace std;
class Queue {
int front, rear;
int queue[5];
public:
Queue() {
front = -1;
rear = -1;
}
void enqueue(int value) {
if (rear == 4) {
cout << "Queue is full!" << endl;
} else {
if (front == -1) front = 0;
rear++;
queue[rear] = value;
cout << value << " enqueued to queue." << endl;
}
}
void dequeue() {
if (front == -1 || front > rear) {
cout << "Queue is empty!" << endl;
} else {
cout << queue[front] << " dequeued from queue." << endl;
front++;
}
}

Page 19
void display() {
if (front == -1 || front > rear) {
cout << "Queue is empty!" << endl;
} else {
cout << "Queue elements: ";
for (int i = front; i <= rear; i++) {
cout << queue[i] << " ";
}
cout << endl;
}
}
};

int main() {
Queue q;
[Link](100);
[Link](200);
[Link](300);
[Link](400);
[Link](500);

[Link]();

[Link]();
[Link]();

[Link]();

[Link](600);
[Link](700);

[Link]();
return 0;
}

Tabulation Sheet

Page 20
INPUT OUTPUT
100 enqueued to queue.
200 enqueued to queue.
300 enqueued to queue.
400 enqueued to queue.
500 enqueued to queue.
Queue elements: 100 200 300 400
500
100 dequeued from queue.
200 dequeued from queue.
Queue elements: 300 400 500
Queue is full!
Queue is full!
Queue elements: 300 400 500
Results
•The program successfully demonstrates the insertion and deletion operations in a queue.
•Elements are inserted at the rear and removed from the front, following the FIFO principle.
•The queue size is limited to 5 elements, and error handling is done for full and empty conditions.

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Page 21
Group / Title: Tree Creation in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Tree Creation in C++
Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


The problem is about creating a binary search tree, which is a data structure used to store values in an ordered

Page 22
manner. The insertion method ensures that each value inserted is placed at the correct position in the tree.

Algorithm
[Link] with an empty tree.
[Link] each value into the tree.
[Link] each insertion:
•If the tree is empty, the node becomes the root.
•If the tree is not empty, compare the value with the current node’s value and move left or right
accordingly.
[Link] the tree using different methods:
•Inorder: left, root, right.
•Preorder: root, left, right.
•Postorder: left, right, root.

Program
#include<iostream>
using namespace std;
class Node {
public:
int data;
Node* left;
Node* right;

Node(int val) {
data = val;
left = right = nullptr;
}
};
class Tree {
public:
Node* root;

Tree() {
root = nullptr;
}

Page 23
Node* insert(Node* node, int data) {
if (node == nullptr) {
return new Node(data);
}
if (data < node->data) {
node->left = insert(node->left, data);
} else {
node->right = insert(node->right, data);
}
return node;
}
void insert(int data) {
root = insert(root, data);
}
void inorder(Node* node) {
if (node == nullptr) {
return;
}
inorder(node->left);
cout << node->data << " ";
inorder(node->right);
}
void inorder() {
inorder(root);
}
void preorder(Node* node) {
if (node == nullptr) {
return;
}
cout << node->data << " ";
preorder(node->left);
preorder(node->right);
}
void preorder() {
preorder(root);
}
void postorder(Node* node) {

Page 24
if (node == nullptr) {
return;
}
postorder(node->left);
postorder(node->right);
cout << node->data << " ";
}
void postorder() {
postorder(root);
}
};
int main() {
Tree tree;
[Link](5);
[Link](3);
[Link](2);
[Link](4);
[Link](7);
[Link](6);
[Link](8);

cout << "Inorder traversal: ";


[Link]();
cout << endl;

cout << "Preorder traversal: ";


[Link]();
cout << endl;

cout << "Postorder traversal: ";


[Link]();
cout << endl;

return 0;
}

Page 25
Tabulation Sheet

INPUT OUTPUT
Inorder traversal: 2 3 4 5 6 7b8
Preorder traversal: 5 3 2 4 7 6 8
Postorder traversal: 2 4 3 6 8 7 5

Results
The tree correctly displays different traversal orders: inorder, preorder, and postorder.

Page 26
Acropolis Institute of Technology and Research, Indore
Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Implementation of Selection Sort in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Implementation of Selection Sort in C++

Neatly Drawn and labeled experimental setup

Page 27
Theoretical solution of the instant problem
Selection Sort is a sorting algorithm that divides the array into two parts: sorted and unsorted. It repeatedly selects
the smallest element from the unsorted part and swaps it with the first unsorted element, growing the sorted
portion step by step.

Algorithm
[Link]
[Link] the array size and array elements.
[Link] the outer loop to iterate from the first element to the second last element of the array.
[Link] each iteration, assume the first unsorted element as the minimum.
[Link] the assumed minimum with the rest of the unsorted elements.
[Link] a smaller element is found, update the minimum’s position.
[Link] the minimum element with the first unsorted element.
[Link] steps 4–7 until the array is sorted.
[Link] the sorted array.
[Link]

Program
#include <iostream>
using namespace std;

void selectionSort(int arr[], int n) {


for (int i = 0; i < n - 1; i++) {

Page 28
int minIndex = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
if (minIndex != i) {
swap(arr[i], arr[minIndex]);
}
}
}

int main() {
int n;
cout << "Enter number of elements: ";
cin >> n;
int arr[n];
cout << "Enter the elements: ";
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
selectionSort(arr, n);
cout << "Sorted array: ";
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
return 0;
}

}Tabulation Sheet

INPUT OUTPUT
Enter number of elements: 4 Sorted array: 14 17 21 45
Enter the elements: 21
45
14
17

Page 29
Results
The program successfully implements the Selection Sort algorithm. It sorts the input array in ascending order as
expected.

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Implementation of Insertion Sort in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Implementation of Insertion Sort in C++
Page 30
Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


Insertion Sort is a simple sorting algorithm that builds the final sorted array one element at a time. It works by
repeatedly picking the next element and placing it in its correct position among the previously sorted
elements.

Algorithm
[Link] with the second element (index 1) as the key.
[Link] the key with elements to its left and find the correct position.
[Link] all elements greater than the key one position to the right.
[Link] the key at its correct position.
[Link] steps 2–4 for all elements in the array.

Program
#include <iostream>
using namespace std;

void insertionSort(int arr[], int n) {


for (int i = 1; i < n; i++) {

Page 31
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j--;
}
arr[j + 1] = key;
}
}

void printArray(int arr[], int n) {


for (int i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}
int main() {
int arr[] = {24, 71, 43, 92, 57};
int n = sizeof(arr) / sizeof(arr[0]);
cout << "Original Array: ";
printArray(arr, n);
insertionSort(arr, n);
cout << "Sorted Array: ";
printArray(arr, n);
return 0;
}

Tabulation Sheet

INPUT OUTPUT
Original Array: 24 71 43 92 57
Sorted Array: 24 43 57 71 92

Results
•The insertion sort algorithm successfully sorts the given input arrays in ascending order.

Page 32
•The algorithm works in O(n²) time complexity in the worst case and O(n) in the best case.
•It is a stable and in-place sorting algorithm

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Implementation of Quick Sort in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Page 33
Grade: Cross the grade.
A B C D F

Tutor

Title
Implementation of Quick Sort in C++

Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


Objective: To sort an array using the Quick Sort algorithm.
Concept: Quick Sort is a divide-and-conquer algorithm. It selects a pivot element, partitions the array into
subarrays (smaller than and greater than the pivot), and recursively sorts the subarrays.
.

Algorithm
[Link] the pivot element.
[Link] elements such that all elements less than the pivot are on the left, and all elements greater
than the pivot are on the right (partition step).
[Link] apply steps 1 and 2 to the left and right subarrays.
[Link] the sorted subarrays with the pivot to produce the sorted array.

Program

Page 34
#include <iostream>
using namespace std;

void quickSort(int arr[], int low, int high) {


if (low < high) {
int pivotIndex = partition(arr, low, high);
quickSort(arr, low, pivotIndex - 1);
quickSort(arr, pivotIndex + 1, high);
}
}

int partition(int arr[], int low, int high) {


int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] < pivot) {
i++;
swap(arr[i], arr[j]);
}
}
swap(arr[i + 1], arr[high]);
return i + 1;
}
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
int main() {
int arr[] = {45, 17, 84, 19, 11, 55};
int n = sizeof(arr) / sizeof(arr[0]);
quickSort(arr, 0, n - 1);
cout << "Sorted array: ";
printArray(arr, n);
return 0;
}

Page 35
}Tabulation Sheet

INPUT OUTPUT
Sorted array: 11 17 19 45 55 84

Results
The Quick Sort program was successfully implemented and tested. The program sorts an input array of integers in
ascending order using the divide-and-conquer approach.

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Implementation of Merge Sort in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Grade and Remarks by the Tutor


1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem

Page 36
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Implementation of Merge Sort in C++

Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


Merge sort is a divide-and-conquer algorithm that recursively divides the array into two halves, sorts them, and
merges the sorted halves into a single sorted array.
.

Algorithm
[Link] the array has one element, return.
[Link] the array into two halves.
[Link] sort the left half.
[Link] sort the right half.
[Link] the two sorted halves into a single sorted array.

Program

Page 37
#include <iostream>
using namespace std;

void merge(int arr[], int left, int mid, int right) {


int n1 = mid - left + 1;
int n2 = right - mid;
int leftArr[n1], rightArr[n2];

for (int i = 0; i < n1; i++)


leftArr[i] = arr[left + i];
for (int j = 0; j < n2; j++)
rightArr[j] = arr[mid + 1 + j];

int i = 0, j = 0, k = left;
while (i < n1 && j < n2) {
if (leftArr[i] <= rightArr[j]) {
arr[k] = leftArr[i];
i++;
} else {
arr[k] = rightArr[j];
j++;
}
k++;
}
while (i < n1) {
arr[k] = leftArr[i];
i++;
k++;
}

while (j < n2) {


arr[k] = rightArr[j];
j++;
k++;
}
}

Page 38
void mergeSort(int arr[], int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;

mergeSort(arr, left, mid);


mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
int main() {
int arr[] = {92, 18, 53, 45, 76, 17};
int arrSize = sizeof(arr) / sizeof(arr[0]);

mergeSort(arr, 0, arrSize - 1);

cout << "Sorted array: ";


for (int i = 0; i < arrSize; i++)
cout << arr[i] << " ";
return 0;
}

Tabulation Sheet

INPUT OUTPUT
Sorted array: 17 18 45 53 76 92

Page 39
Results
The merge sort algorithm successfully sorts an array of integers in ascending order. The program follows the
divide-and-conquer strategy, ensuring efficiency with a time complexity of O(n log n).

Acropolis Institute of Technology and Research, Indore


Department of CSE (Artificial Intelligence & Machine Learning)
Group / Title: Binary Search Implementation in C++
Lab: Data Structure (AL303)

EVALUATION RECORD Type/ Lab Session:


Name Aditya Anant Patil Enrollment No. 0827AL231013
Performing on First submission Second submission
Extra Regular

Page 40
Grade and Remarks by the Tutor
1. Clarity about the objective of experiment
2. Clarity about the Outcome
3. Submitted the work in desired format
4. Shown capability to solve the problem
5. Contribution to the team work

Additional remarks

Grade: Cross the grade.


A B C D F

Tutor

Title
Binary Search Implementation in C++

Neatly Drawn and labeled experimental setup

Theoretical solution of the instant problem


Binary search finds an element in a sorted array by repeatedly halving the search range. Compare the target with
the middle element: adjust the range based on whether the target is smaller or larger. Repeat until found or
range is empty.
.

Algorithm
[Link] with a sorted array and a key to find.
[Link] two pointers, low at the first index and high at the last index of the array.

Page 41
[Link] the following steps until low is greater than high:
•Calculate the mid index: mid = (low + high) / 2.
•Compare the key with the middle element of the array.
•If the key is equal to the middle element, the search is successful, and return the index.
•If the key is less than the middle element, adjust high = mid - 1.
•If the key is greater than the middle element, adjust low = mid + 1.
[Link] the key is not found, return -1.

Program
#include <iostream>
using namespace std;
int binarySearch(int arr[], int size, int key) {
int low = 0, high = size - 1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == key)
return mid;
else if (arr[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
int main() {
int arr[] = {21, 54, 48, 82, 76, 63, 77, 55, 75};
int size = sizeof(arr) / sizeof(arr[0]);
int key;
cout << "Enter the number to search: ";
cin >> key;
int result = binarySearch(arr, size, key);
if (result != -1)
cout << "Element found at index: " << result << endl;
else
cout << "Element not found." << endl;

Page 42
return 0;
}

Tabulation Sheet

INPUT OUTPUT
Enter the number to search: 82 Element found at index: 3

Results
The binary search algorithm is successfully implemented and tested. It efficiently finds the index of a given key in a
sorted array in O(log n) time complexity.

Page 43

You might also like