Ss 1
Ss 1
In this article, I will cover some common sorting algorithms in computer science. Sorting
algorithms are important to study because they can often reduce the complexity of a problem.
They also have direct applications in searching algorithms, database algorithms, and much
more.
Bubble Sort
Selection Sort
Insertion Sort
Merge Sort
Quick Sort
Bucket Sort
function swap(arr, a, b) {
let temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
We will be comparing elements a lot so I think it's a good idea to write a function for just
that:
const Compare = {
LESS_THAN: -1,
BIGGER_THAN: 1
};
function defaultCompare(a, b) {
if (a === b) {
return 0;
}
return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN;
}