Data Structure Using C (2) New Done
Data Structure Using C (2) New Done
1
MAHARASHTRA STATE
BOARD OF TECHNICAL EDUCATION
Certificate
This is to certify that Mr. /Ms Abhira Gangadhar Powade ,
Dhanshri Suryakant Bande. roll no. 933, 962. of third semester of
diploma in Information Technology of Institute, GOVERNMENT
POLYTECHNIC, NANDED(0020) has completed the Micro
Project satisfactorily in Subject Data structures using c (22317)
for the academic year 2023-2024 as prescribed in the curriculum.
Place: NANDED
2
ANEEXURE I
3
…………………………………………………………………….
4
CONTENT
Sr. Chapter/Title
No.
1. Introduction
5
Selection Sort
6
#bubble sort
7
#Selection Sort
8
Implementation Of Selection Sort
And Bubble Sort
#include <iostream>
using namespace std;
void Selection_Sort(int arr[], int n)
{
for(int i = 0; i < n - 1; ++i)
{
int min_index = i;
for(int j = i + 1; j < n; ++j)
{
if(arr[j] < arr[min_index])
min_index = j;
}
swap(arr[i], arr[min_index]);
}
}
int main()
{
int n = 5;
int arr[5] = {2, 0, 1, 4, 3};
Selection_Sort(arr, n);
cout<<"The Sorted Array by using Selection Sort is : ";
for(int i = 0; i < n; ++i)
cout<<arr[i]<<" ";
return 0;
}
Output
The Sorted Array by using Selection Sort is : 0 1 2 3 4
9
Implementation of Bubble Sort
Below is the implementation of the above-explained algorithm.
#include <iostream>
using namespace std;
void Bubble_Sort(int arr[], int n)
{
for(int i = 1; i < n; ++i)
{
for(int j = 0; j <= (n - i - 1); ++j)
{
if(arr[j] > arr[j + 1])
swap(arr[j], arr[j + 1]);
}
}
}
int main()
{
int n = 5;
int arr[5] = {2, 0, 1, 4, 3};
Bubble_Sort(arr, n);
cout<<"The Sorted Array by using Bubble Sort is : ";
for(int i = 0; i < n; ++i)
cout<<arr[i]<<" ";
return 0;
}
Output
The Sorted Array by using Bubble Sort is : 0 1 2 3 4
10
Difference between Selection sort and bubble sort
4. Its Time complexity in the worst Its Time complexity in Worst case is
case is O(N^2) O(N^2)
5. This sorting algorithm uses the This sorting algorithm uses exchanging
selection method method
11
References
• www.goggle.com
• https://www.geeksforgeeks.org
• Data structures using C textbook
THANK YOU
12