MCPcopy Create free account
hub / github.com/geekcomputers/Python / timSort

Function timSort

Sorting Algorithms/Tim_sort.py:66–89  ·  view source on GitHub ↗
(arr, n)

Source from the content-addressed store, hash-verified

64# iterative Timsort function to sort the
65# array[0...n-1] (similar to merge sort)
66def timSort(arr, n):
67 # Sort individual subarrays of size RUN
68 for i in range(0, n, RUN):
69 insertionSort(arr, i, min((i + 31), (n - 1)))
70
71 # start merging from size RUN (or 32). It will merge
72 # to form size 64, then 128, 256 and so on ....
73 size = RUN
74 while size < n:
75 # pick starting point of left sub array. We
76 # are going to merge arr[left..left+size-1]
77 # and arr[left+size, left+2*size-1]
78 # After every merge, we increase left by 2*size
79 for left in range(0, n, 2 * size):
80 # find ending point of left sub array
81 # mid+1 is starting point of right sub array
82 mid = left + size - 1
83 right = min((left + 2 * size - 1), (n - 1))
84
85 # merge sub array arr[left.....mid] &
86 # arr[mid+1....right]
87 merge(arr, left, mid, right)
88
89 size = 2 * size
90
91
92# utility function to print the Array

Callers 1

Tim_sort.pyFile · 0.85

Calls 2

insertionSortFunction · 0.85
mergeFunction · 0.70

Tested by

no test coverage detected