Today, I will discuss Some important Sorting Techniques with their code. 1)Selection Sort Explanation: We will select minimum among all unsorted elements and swap it with first unsorted element. Time complexity: O(N^2)
int n=5;
int arr[]={9,1,5,6,3};
for(int i=0 ; i<5 ; i++){
int pos=0,mn=1e5;
for(int j=i ; j<n ; j++){
if(arr[j]<mn){
pos=j;
mn=arr[j];
}
}
swap(arr[i],arr[pos]);
}
for(int i=0 ; i<n ; i++){
cout<<arr[i]<<' ';
}
2)Bubble Sort Explanation: We will send largest element to last by repeatedly swapping the adjacent elements if they are in the wrong order. tome complexity O(N^2) int n=5; int arr[]={9,1,5,6,3}; for(int i=n-1 ; i>=0 ; i--){ for(int j=0 ; j<i ; j++){ if(arr[j]>arr[j+1]) swap(arr[j],arr[j+1]); } } for(int i=0 ; i<n ; i++) cout<<arr[i]<<' ';



