data_structure) 6 sorting algorithms using python(2)
Hello, this is second posting about sorting algorithms. I'll show you rest 3 sorting algorithms. Fourth is merge sort. This algorithm has O(nlogn) time complexity regardless Best, average, Worst case. I think this is really great. Also, this algorithm is stable. def __merge ( data , left , middle , right ): a = data[left:middle + 1 ] b = data[middle + 1 : right + 1 ] i = 0 j = 0 k = left while i < len (a) and j < len (b): if a[i] <= b[j]: data[k] = a[i] i += 1 else : data[k] = b[j] j += 1 k += 1 while i < len (a): data[k] = a[i] i += 1 k += 1 while j < len (b): data[k] = b[j] j += 1 k += 1 def __merge_sort ( data , left , right ): if left >= right: return m = int ((left + right) / 2 ) __merge_sort(data, left, m) ...