Sorting is the rearrangement of elements in into a specific order. Sorting algorithms helps in making the solution easier and efficient. Some basic yet important sort algorithms, that one must know are as follows:

1. Selection Sort: It sorts an array by repeatedly finding the minimum element (considering decresing order) from unsorted part and putting it at the beginning.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/05c3738f-82cb-40b4-b4a6-bcddefee899d/675707ad-630e-4d57-9168-6cd317d00c14_1614779897.159416.png

void selection_sort(vector <int> arr, int n){
	int min_index=i;
	for(int j=i;j<n;j++){
		if(arr[j]<arr[min_index])
			min_index=j;
		}
		swap(arr[i],arr[min_index]);
	}

2. Bubble Sort: It works by repeatedly swapping the adjacent wrong elements.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9da95071-fe6f-4bdd-8c5a-c1653acc574b/41955331-e14e-40ee-80ce-ea8dd3d7c7e5_1614779928.7023816.png

void bubble_sort(vector <int> arr, int n){
	for(int itr=1;itr<n;itr++){
		for(int j=0;j<(n-itr-);j++){
			if(arr[j]>arr[j+1])
				swap(arr[j],arr[j+1]);
		}
	}
}

Recursive Bubble Sort:

void bubble_sort(vector <int> arr, int n){
    if (n == 1)        // Base case
        return;

    for (int i=0; i<n-1; i++)
        if (arr[i] > arr[i+1])
            swap(arr[i], arr[i+1]);

    bubble_sort(arr, n-1);
}

3. Insertion Sort: Values from unsorted part is picked and placed at the sorted position.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/03c78a41-7b67-4bda-b280-679b34add954/6f71e5ee-58bf-42db-88b5-82cf4ea039b8_1614779989.7518167.png

void insertion_sort(vector <int> arr, int n){
	for(int i=1;j<n;j++){
		int e=arr[i];
		int j=i-1;
		while(j>=0 && arr[j]<arr[j]>e){
			a[j+1]=a[j];
			j=j-1;
		}
		a[j+1]=e;
	}

4. Shell Sort: It is the variation of Insertion sort, as here the elements are moved far ahead.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/15b00387-3393-4527-be4d-8a54f0a1f9cf/4b4bb35e-fc5d-4345-a138-e16ef2b45239_1614780211.058775.png