Insertion Sort

insertion sort is one of the fastest algorithms for sorting very small arrays, even faster than quicksort. Performance: Worst case: O(n2) Average case: O(n2) Best case: O(n) <?php function insertionSort(array $array) { $length=count($array); for ($i=1;$i<$length;$i++) { $element=$array[$i]; //put second element…

Merge Sort

<?php $arr = array( 6,1,3,7,5,2,3,4,45,5,4,75,8,6,78,7980890,2,4,2,432,5,34,5634,34,5); echo “<br>”.implode(‘,’,$arr).”<br>”; $arr=mergesort($arr); echo implode(‘,’,$arr); function mergesort($numlist) { if(count($numlist) == 1 ) return $numlist; $mid = count($numlist) / 2; $left = array_slice($numlist, 0, $mid); $right = array_slice($numlist, $mid); $left = mergesort($left); $right = mergesort($right); return…