22BPS1201 - Ips-1 Daa
22BPS1201 - Ips-1 Daa
22BPS1201 - Ips-1 Daa
NAME: KOUSHIK.Y
NO:22BPS1201
2. BUBBLE SORT
CODE:
#include <iostream>
#include<chrono>
#include<algorithm>
#include<vector>
int main()
{
int n;
cout<<"enter the size of array"<<endl;
cin>>n;
int arr[n];
for(int k=0;k<n;k++){
cout<<arr[k];
}
auto stop = chrono::high_resolution_clock::now();
cout<<""<<endl;
return 0;
}
OUTPUT:
BEST CASE:
AVERAGE CASE:
WORST CASE:
The provided code implements a bubble sort algorithm
to sort an array of integers. Let's analyze its time
complexity in terms of Big O notation, denoted as
(T(n)), where (n) is the size of the input array.
3. Consider an array of A[1, 2, 3, ..., n] be an array of n distinct numbers. If i < j and A[i] >
A[j], then we call the pair (i, j) as an inversion of A. For example, the five inversions in the
array A :< 2, 3, 8, 6, 1 > are (1, 5), (2, 5), (3, 4), (3, 5), (4, 5).
CODE:
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"enter the size of array"<<endl;
cin>>n;
int arr[n];
for(int i=1;i<=n;i++){ // O(n) - Linear time for iterating through the array
once
cin>>arr[i];
}
OUTPUT: