Shell Sort in ( C and Python 3 )
Shell Sorting
Shell sort is a highly efficient sorting algorithm and is based on insertion sort algorithm. This algorithm avoids large shifts as in case of insertion sort, if the smaller value is to the far right and has to be moved to the far left.
This algorithm uses insertion sort on a widely spread elements, first to sort them and then sorts the less widely spaced elements. This spacing is termed as interval. This interval is calculated based on Knuth's formula as −
Best Case Scenario : O( n )
Average Case Scenario : O( n log n )
Worst Case Scenario : O( n ^ 1.25 )
Knuth's Formula
h = h * 3 + 1
where −
h is interval with initial value 1
This algorithm is quite efficient for medium-sized data sets as its average and worst-case complexity of this algorithm depends on the gap sequence the best known is Ο(n), where n is the number of items. And the worst case space complexity is O(n).
Shell Sorting in C
Shell Sorting in Python 3
asokaosk
Comments
Post a Comment