Sorting
Sorting
smaller subarrays, sorting each subarray, and then merging the sorted subarrays
back together to form the final sorted array.
2.These subarrays are further divided into two halves. Now they become array of
unit length that can no longer be divided and array of unit length are always
sorted.
3.mergeing the unit length of subarrays into sorted subarrays.
4.These sorted subarrays are merged together, and we get bigger sorted subarrays.
merge(arr, l, m, r);
}
}
while (i < j) {
Bubble sort is a simple sorting algorithm that works by comparing the adjacent
elements in the list and swapping them if the elements are not in the specified
order.
The outer loop will run from i = 0 to i < n – 1, where n is the number of elements
in the list.
The inner loop will run from j = 0 to j < n – i – 1. It is because, after each
iteration of the outer loop, one element at the end (or at the start if the order
is decreasing order) will be in its right place so we can leave it as it is.
This process will be repeated till the conditions of the loop are satisfied.
Selection sort is a simple and efficient sorting algorithm that works by repeatedly
selecting the smallest (or largest) element from the unsorted portion of the list
and moving it to the sorted portion of the list.