diff --git a/curriculum/challenges/_meta/rosetta-code/meta.json b/curriculum/challenges/_meta/rosetta-code/meta.json
index 9c123a50fd..3e2c3538a0 100644
--- a/curriculum/challenges/_meta/rosetta-code/meta.json
+++ b/curriculum/challenges/_meta/rosetta-code/meta.json
@@ -329,8 +329,72 @@
"Sorting algorithms/Bead sort"
],
[
- "5a23c84252665b21eecc8002",
- "Sorting algorithms/Bogosort"
+ "5a23c84252665b21eecc8002",
+ "Sorting algorithms/Bogosort"
+ ],
+ [
+ "5a23c84252665b21eecc8003",
+ "Sorting algorithms/Bubble sort"
+ ],
+ [
+ "5a23c84252665b21eecc8004",
+ "Sorting algorithms/Cocktail sort"
+ ],
+ [
+ "5a23c84252665b21eecc8005",
+ "Sorting algorithms/Comb sort"
+ ],
+ [
+ "5a23c84252665b21eecc8006",
+ "Sorting algorithms/Counting sort"
+ ],
+ [
+ "5a23c84252665b21eecc8007",
+ "Sorting algorithms/Gnome sort"
+ ],
+ [
+ "5a23c84252665b21eecc8008",
+ "Sorting algorithms/Heapsort"
+ ],
+ [
+ "5a23c84252665b21eecc8009",
+ "Sorting algorithms/Insertion sort"
+ ],
+ [
+ "5a23c84252665b21eecc800a",
+ "Sorting algorithms/Merge sort"
+ ],
+ [
+ "5a23c84252665b21eecc800b",
+ "Sorting algorithms/Pancake sort"
+ ],
+ [
+ "5a23c84252665b21eecc800c",
+ "Sorting algorithms/Permutation sort"
+ ],
+ [
+ "5a23c84252665b21eecc800d",
+ "Sorting algorithms/Quicksort"
+ ],
+ [
+ "5a23c84252665b21eecc800e",
+ "Sorting algorithms/Radix sort"
+ ],
+ [
+ "5a23c84252665b21eecc800f",
+ "Sorting algorithms/Selection sort"
+ ],
+ [
+ "5a23c84252665b21eecc8010",
+ "Sorting algorithms/Shell sort"
+ ],
+ [
+ "5a23c84252665b21eecc8012",
+ "Sorting algorithms/Stooge sort"
+ ],
+ [
+ "5a23c84252665b21eecc8013",
+ "Sorting algorithms/Strand sort"
],
[
"594ecc0d9a8cf816e3340187",
diff --git a/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sorting-algorithms-bubble-sort.md b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sorting-algorithms-bubble-sort.md
new file mode 100644
index 0000000000..76d06b50d4
--- /dev/null
+++ b/curriculum/challenges/english/08-coding-interview-prep/rosetta-code/sorting-algorithms-bubble-sort.md
@@ -0,0 +1,87 @@
+---
+id: 5a23c84252665b21eecc8003
+title: Sorting algorithms/Bubble sort
+challengeType: 5
+---
+
+## Description
+
+repeat
+ hasChanged := false
+ decrement itemCount
+ repeat with index from 1 to itemCount
+ if (item at index) > (item at (index + 1))
+ swap (item at index) with (item at (index + 1))
+ hasChanged := true
+until hasChanged = false
+
+bubblesort
should be a function.
+ testString: assert(typeof bubblesort == 'function', 'bubblesort
should be a function.');
+ - text: bubblesort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(bubblesort([25, 32, 12, 7, 20])), 'bubblesort([25, 32, 12, 7, 20])
should return a array.');
+ - text: bubblesort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(bubblesort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'bubblesort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: bubblesort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(bubblesort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'bubblesort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: bubblesort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(bubblesort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'bubblesort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: bubblesort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(bubblesort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'bubblesort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: bubblesort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(bubblesort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'bubblesort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+
+function cocktailSort( A : list of sortable items ) + do + swapped := false + for each i in 0 to length( A ) - 2 do + if A[ i ] > A[ i+1 ] then // test whether the two + // elements are in the wrong + // order + swap( A[ i ], A[ i+1 ] ) // let the two elements + // change places + swapped := true; + if swapped = false then + // we can exit the outer loop here if no swaps occurred. + break do-while loop; + swapped := false + for each i in length( A ) - 2 down to 0 do + if A[ i ] > A[ i+1 ] then + swap( A[ i ], A[ i+1 ] ) + swapped := true; + while swapped; // if no elements have been swapped, + // then the list is sorted ++Write a function that sorts a given array using cocktail sort. + + +## Instructions +
cocktailSort
should be a function.
+ testString: assert(typeof cocktailSort == 'function', 'cocktailSort
should be a function.');
+ - text: cocktailSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(cocktailSort([25, 32, 12, 7, 20])), 'cocktailSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: cocktailSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(cocktailSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'cocktailSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: cocktailSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(cocktailSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'cocktailSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: cocktailSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(cocktailSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'cocktailSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: cocktailSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(cocktailSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'cocktailSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: cocktailSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(cocktailSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'cocktailSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function combsort(array input) + gap := input.size //initialize gap size + loop until gap = 1 and swaps = 0 + //update the gap value for a next comb. Below is an example + gap := int(gap / 1.25) + if gap < 1 + //minimum gap is 1 + gap := 1 + end if + i := 0 + swaps := 0 //see Bubble Sort for an explanation + //a single "comb" over the input list + loop until i + gap >= input.size //see Shell sort for similar idea + if input[i] > input[i+gap] + swap(input[i], input[i+gap]) + swaps := 1 // Flag a swap has occurred, so the + // list is not guaranteed sorted + end if + i := i + 1 + end loop + end loop +end function ++Write a function that sorts a given array using Comb sort. +
combSort
should be a function.
+ testString: assert(typeof combSort == 'function', 'combSort
should be a function.');
+ - text: combSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(combSort([25, 32, 12, 7, 20])), 'combSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: combSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(combSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'combSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: combSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(combSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'combSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: combSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(combSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'combSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: combSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(combSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'combSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: combSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(combSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'combSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function countingSort(array, min, max): + count: array of (max - min + 1) elements + initialize count with 0 + for each number in array do + count[number - min] := count[number - min] + 1 + done + z := 0 + for i from min to max do + while ( count[i - min] > 0 ) do + array[z] := i + z := z+1 + count[i - min] := count[i - min] - 1 + done + done ++Write a function to implement the above pseudo code. The function should return the sorted array. +
countSort
should be a function.
+ testString: assert(typeof countSort == 'function', 'countSort
should be a function.');
+ - text: countSort([25, 32, 12, 7, 20],7, 32)
should return a array.
+ testString: assert(Array.isArray(countSort([25, 32, 12, 7, 20], 7, 32)), 'countSort([25, 32, 12, 7, 20],7, 32)
should return a array.');
+ - text: countSort([25, 32, 12, 7, 20],7, 32)
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(countSort([25, 32, 12, 7, 20], 7, 32), [7, 12, 20, 25, 32], 'countSort([25, 32, 12, 7, 20],7, 32)
should return [7, 12, 20, 25, 32]
.');
+ - text: countSort([38, 45, 35, 8, 13],8, 45)
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(countSort([38, 45, 35, 8, 13], 8, 45), [8, 13, 35, 38, 45], 'countSort([38, 45, 35, 8, 13],8, 45)
should return [8, 13, 35, 38, 45]
.');
+ - text: countSort([43, 36, 20, 34, 24],20, 43)
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(countSort([43, 36, 20, 34, 24], 20, 43), [20, 24, 34, 36, 43], 'countSort([43, 36, 20, 34, 24],20, 43)
should return [20, 24, 34, 36, 43]
.');
+ - text: countSort([12, 33, 26, 18, 1, 16, 38],1, 38)
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(countSort([12, 33, 26, 18, 1, 16, 38], 1, 38), [1, 12, 16, 18, 26, 33, 38], 'countSort([12, 33, 26, 18, 1, 16, 38],1, 38)
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: countSort([3, 39, 48, 16, 1, 4, 29],1, 48)
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(countSort([3, 39, 48, 16, 1, 4, 29], 1, 48), [1, 3, 4, 16, 29, 39, 48], 'countSort([3, 39, 48, 16, 1, 4, 29],1, 48)
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function gnomeSort(a[0..size-1]) + i := 1 + j := 2 + while i < size do + if a[i-1] <= a[i] then + /// for descending sort, use >= for comparison + i := j + j := j + 1 + else + swap a[i-1] and a[i] + i := i - 1 + if i = 0 then + i := j + j := j + 1 + endif + endif + done ++Write a function to implement the above pseudo code. The function should return the sorted array. +
gnomeSort
should be a function.
+ testString: assert(typeof gnomeSort == 'function', 'gnomeSort
should be a function.');
+ - text: gnomeSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(gnomeSort([25, 32, 12, 7, 20])), 'gnomeSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: gnomeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(gnomeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'gnomeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: gnomeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(gnomeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'gnomeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: gnomeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(gnomeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'gnomeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: gnomeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(gnomeSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'gnomeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: gnomeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(gnomeSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'gnomeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function heapSort(a, count) is + input: an unordered array a of length count+
+ (first place a in max-heap order) + heapify(a, count)
+ end := count - 1 + while end > 0 do + (swap the root(maximum value) of the heap with the + last element of the heap) + swap(a[end], a[0]) + (decrement the size of the heap so that the previous + max value will stay in its proper place) + end := end - 1 + (put the heap back in max-heap order) + siftDown(a, 0, end) +
+function heapify(a,count) is + (start is assigned the index in a of the last parent node) + start := (count - 2) / 2+Write a function to sort a collection of integers using heapsort. +
+ while start ≥ 0 do + (sift down the node at index start to the proper place + such that all nodes below the start index are in heap + order) + siftDown(a, start, count-1) + start := start - 1 + (after sifting down the root all nodes/elements are in heap order)
+function siftDown(a, start, end) is + (end represents the limit of how far down the heap to sift) + root := start
+ while root * 2 + 1 ≤ end do (While the root has at least one child) + child := root * 2 + 1 (root*2+1 points to the left child) + (If the child has a sibling and the child's value is less than its sibling's...) + if child + 1 ≤ end and a[child] < a[child + 1] then + child := child + 1 (... then point to the right child instead) + if a[root] < a[child] then (out of max-heap order) + swap(a[root], a[child]) + root := child (repeat to continue sifting down the child now) + else + return +
heapSort
should be a function.
+ testString: assert(typeof heapSort == 'function', 'heapSort
should be a function.');
+ - text: heapSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(heapSort([25, 32, 12, 7, 20])), 'heapSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: heapSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(heapSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'heapSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: heapSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(heapSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'heapSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: heapSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(heapSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'heapSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: heapSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(heapSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'heapSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: heapSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(heapSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'heapSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function insertionSort(array A) + for i from 1 to length[A]-1 do + value := A[i] + j := i-1 + while j >= 0 and A[j] > value do + A[j+1] := A[j] + j := j-1 + done + A[j+1] = value + done ++Write a function that performs insertion sort on a given array. The function should return the sorted array. +
insertionSort
should be a function.
+ testString: assert(typeof insertionSort == 'function', 'insertionSort
should be a function.');
+ - text: insertionSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(insertionSort([25, 32, 12, 7, 20])), 'insertionSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: insertionSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(insertionSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'insertionSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: insertionSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(insertionSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'insertionSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: insertionSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(insertionSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'insertionSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: insertionSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(insertionSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'insertionSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: insertionSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(insertionSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'insertionSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function mergesort(m) + var list left, right, result + if length(m) ≤ 1 + return m + else + var middle = length(m) / 2 + for each x in m up to middle - 1 + add x to left + for each x in m at and after middle + add x to right + left = mergesort(left) + right = mergesort(right) + if last(left) ≤ first(right) + append right to left + return left + result = merge(left, right) + return result+
+function merge(left,right) + var list result + while length(left) > 0 and length(right) > 0 + if first(left) ≤ first(right) + append first(left) to result + left = rest(left) + else + append first(right) to result + right = rest(right) + if length(left) > 0 + append rest(left) to result + if length(right) > 0 + append rest(right) to result + return result +
mergeSort
should be a function.
+ testString: assert(typeof mergeSort == 'function', 'mergeSort
should be a function.');
+ - text: mergeSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(mergeSort([25, 32, 12, 7, 20])), 'mergeSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: mergeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(mergeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'mergeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: mergeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(mergeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'mergeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: mergeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(mergeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'mergeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: mergeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(mergeSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'mergeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: mergeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(mergeSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'mergeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++Before: +6 7 8 9 2 5 3 4 1 +After: +9 8 7 6 2 5 3 4 1 ++Only one end of the list can be flipped; this should be the low end, but the high end is okay if it's easier to code or works better, but it must be the same end for the entire solution. (The end flipped can't be arbitrarily changed.) +
pancakeSort
should be a function.
+ testString: assert(typeof pancakeSort == 'function', 'pancakeSort
should be a function.');
+ - text: pancakeSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(pancakeSort([25, 32, 12, 7, 20])), 'pancakeSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: pancakeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(pancakeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'pancakeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: pancakeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(pancakeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'pancakeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: pancakeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(pancakeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'pancakeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: pancakeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(pancakeSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'pancakeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: pancakeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(pancakeSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'pancakeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++while not InOrder(list) do + nextPermutation(list) +done ++
permutationSort
should be a function.
+ testString: assert(typeof permutationSort == 'function', 'permutationSort
should be a function.');
+ - text: permutationSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(permutationSort([25, 32, 12, 7, 20])), 'permutationSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: permutationSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(permutationSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'permutationSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: permutationSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(permutationSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'permutationSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: permutationSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(permutationSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'permutationSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: permutationSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(permutationSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'permutationSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: permutationSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(permutationSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'permutationSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++function quicksort(array) + less, equal, greater := three empty arrays + if length(array) > 1 + pivot := select any element of array + for each x in array + if x < pivot then add x to less + if x = pivot then add x to equal + if x > pivot then add x to greater + quicksort(less) + quicksort(greater) + array := concatenate(less, equal, greater) ++A better quicksort algorithm works in place, by swapping elements within the array, to avoid the memory allocation of more arrays. +
+function quicksort(array) + if length(array) > 1 + pivot := select any element of array + left := first index of array + right := last index of array + while left ≤ right + while array[left] < pivot + left := left + 1 + while array[right] > pivot + right := right - 1 + if left ≤ right + swap array[left] with array[right] + left := left + 1 + right := right - 1 + quicksort(array from first index to right) + quicksort(array from left to last index) ++Quicksort has a reputation as the fastest sort. Optimized variants of quicksort are common features of many languages and libraries. One often contrasts quicksort with merge sort, because both sorts have an average time of O(n log n). +
+ "On average, mergesort does fewer comparisons than quicksort, so it may be better when complicated comparison routines are used. Mergesort also takes advantage of pre-existing order, so it would be favored for using sort() to merge several sorted arrays. On the other hand, quicksort is often faster for small arrays, and on arrays of a few distinct values, repeated many times." — http://perldoc.perl.org/sort.html ++Quicksort is at one end of the spectrum of divide-and-conquer algorithms, with merge sort at the opposite end. +
quickSort
should be a function.
+ testString: assert(typeof quickSort == 'function', 'quickSort
should be a function.');
+ - text: quickSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(quickSort([25, 32, 12, 7, 20])), 'quickSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: quickSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(quickSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'quickSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: quickSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(quickSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'quickSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: quickSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(quickSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'quickSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: quickSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(quickSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'quickSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: quickSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(quickSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'quickSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+radixSort
should be a function.
+ testString: assert(typeof radixSort == 'function', 'radixSort
should be a function.');
+ - text: radixSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(radixSort([25, 32, 12, 7, 20])), 'radixSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: radixSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(radixSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'radixSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: radixSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(radixSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'radixSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: radixSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(radixSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'radixSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: radixSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(radixSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'radixSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: radixSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(radixSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'radixSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+selectionSort
should be a function.
+ testString: assert(typeof selectionSort == 'function', 'selectionSort
should be a function.');
+ - text: selectionSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(selectionSort([25, 32, 12, 7, 20])), 'selectionSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: selectionSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(selectionSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'selectionSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: selectionSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(selectionSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'selectionSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: selectionSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(selectionSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'selectionSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: selectionSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(selectionSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'selectionSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: selectionSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(selectionSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'selectionSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+shellSort
should be a function.
+ testString: assert(typeof shellSort == 'function', 'shellSort
should be a function.');
+ - text: shellSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(shellSort([25, 32, 12, 7, 20])), 'shellSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: shellSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(shellSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'shellSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: shellSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(shellSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'shellSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: shellSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(shellSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'shellSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: shellSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(shellSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'shellSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: shellSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(shellSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'shellSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
++algorithm stoogesort(array L, i = 0, j = length(L)-1) + if L[j] < L[i] then + L[i] ↔ L[j] + if j - i > 1 then + t := (j - i + 1)/3 + stoogesort(L, i , j-t) + stoogesort(L, i+t, j ) + stoogesort(L, i , j-t) + return L ++
stoogeSort
should be a function.
+ testString: assert(typeof stoogeSort == 'function', 'stoogeSort
should be a function.');
+ - text: stoogeSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(stoogeSort([25, 32, 12, 7, 20])), 'stoogeSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: stoogeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(stoogeSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'stoogeSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: stoogeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(stoogeSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'stoogeSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: stoogeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(stoogeSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'stoogeSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: stoogeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(stoogeSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'stoogeSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: stoogeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(stoogeSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'stoogeSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+strandSort
should be a function.
+ testString: assert(typeof strandSort == 'function', 'strandSort
should be a function.');
+ - text: strandSort([25, 32, 12, 7, 20])
should return a array.
+ testString: assert(Array.isArray(strandSort([25, 32, 12, 7, 20])), 'strandSort([25, 32, 12, 7, 20])
should return a array.');
+ - text: strandSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.
+ testString: assert.deepEqual(strandSort([25, 32, 12, 7, 20]), [7, 12, 20, 25, 32], 'strandSort([25, 32, 12, 7, 20])
should return [7, 12, 20, 25, 32]
.');
+ - text: strandSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.
+ testString: assert.deepEqual(strandSort([38, 45, 35, 8, 13]), [8, 13, 35, 38, 45], 'strandSort([38, 45, 35, 8, 13])
should return [8, 13, 35, 38, 45]
.');
+ - text: strandSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.
+ testString: assert.deepEqual(strandSort([43, 36, 20, 34, 24]), [20, 24, 34, 36, 43], 'strandSort([43, 36, 20, 34, 24])
should return [20, 24, 34, 36, 43]
.');
+ - text: strandSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.
+ testString: assert.deepEqual(strandSort([12, 33, 26, 18, 1, 16, 38]), [1, 12, 16, 18, 26, 33, 38], 'strandSort([12, 33, 26, 18, 1, 16, 38])
should return [1, 12, 16, 18, 26, 33, 38]
.');
+ - text: strandSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.
+ testString: assert.deepEqual(strandSort([3, 39, 48, 16, 1, 4, 29]), [1, 3, 4, 16, 29, 39, 48], 'strandSort([3, 39, 48, 16, 1, 4, 29])
should return [1, 3, 4, 16, 29, 39, 48]
.');
+```
+
+