This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function quickSort(arr){ | |
const size = arr.length; | |
if(size === 0) return []; | |
else { | |
let pivot = arr[0]; | |
let left = []; | |
let right = []; | |
for(let i = 1; i<size;i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function merge(left, right){ | |
const list = []; | |
while(left.length && right.length){ | |
if(left[0] < right[0]){ | |
list.push(left[0]) | |
left.shift(); | |
} else { | |
list.push(right[0]) | |
right.shift(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countingSort(arr){ | |
const aux = Array.from({length: Math.max(...arr)+1}, (v)=> 0) | |
for(let i = 0; i<arr.length; i++){ | |
aux[arr[i]] = ++aux[arr[i]]; | |
} | |
for (let i = 1; i < aux.length; i++) { | |
let prev = aux[i-1]; | |
let next = prev + aux[i]; | |
aux[i] = next; | |
} |