Double Insertion Sort is a variation on Insertion Sort that
Solution
a) Cost of double insertion sort will also be O(n*n) same as insertion sort because, we have to iterate the above mentioned method n times and for each iteration the worst case time complexity can be O(n) i.e pushing till the last of the array.
b)
def double_insertion_sort(arr):
if len(arr) % 2 == 1:
#odd lenth
mid = len(arr) /2
count = 1
while mid - count >= 0:
left = mid -count
right = mid + count
if arr[left] >= arr[right]:
arr[left], arr[right] = arr[right] , arr[left]
ind = left +1
while arr[ind] <= arr[left] :
arr[left] , arr[ind] = arr[ind] , arr[left]
left +=1
ind +=1
ind =right -1
while ind >=0 and arr[ind] >= arr[right] :
arr[right] , arr[ind] = arr[ind] , arr[right]
right -=1;
ind -=1
count +=1
else:
mid = len(arr) /2
left = mid-1
right = mid
while left >= 0 and right <= len(arr) -1:
if arr[left] > arr[right]:
arr[left], arr[right] = arr[right] , arr[left]
ind = left +1
while arr[ind] < arr[left] :
arr[left] , arr[ind] = arr[ind] , arr[left]
left +=1
ind +=1
ind =right -1
while arr[ind] > arr[right] :
arr[right] , arr[ind] = arr[ind] , arr[right]
right -=1;
ind -=1
left -=1
right +=1
print arr
arr = [-8,4 ,-8 , 3, 2 , 2 , -8 , - 6 , 56 , 43, -8777]
double_insertion_sort(arr)
arr = [-8,4 ,-8 , 3, 2 , 2 , -8 , - 6 , 56 , 43, -8777, -9999999 ]
double_insertion_sort(arr)
c) running time is same as standard inserion sort.

