[算法] Elementary Sorts练习
本作业帖用于练习http://algs4.cs.princeton.edu/21elementary/里面的作业。
Stoogesort. Analyze the running time andcorrectness of the following recursive sorting algorithm: if theleftmost item is larger than the rightmost item, swap them. Ifthere are 2 or more items in the current subarray, (i) sort theinitial two-thirds of the array recursively, (ii) sort the finaltwo-thirds of the array, (iii) sort the initial two-thirds of thearray again. StoogeSort时间复杂度为O(_n_log3 / log 1.5 )= O(_n_2.7095…),比合并排序慢,甚至比冒泡排序慢,仅用于低效简单排序示范。
Guess-sort. Pick two indices i and j atrandom; if a[i] > a[j], then swap them.