|
|
|
|
|
by zoomablemind
1453 days ago
|
|
TFA seems to be a somewhat wasteful version of an algo which in my mind I call 'sinkersort' or 'minsort': for (i=0; i<n; ++i)
for (j=i+1; j<n; ++j)
if (a[j] < a[i])
swap(a[j], a[i]);
Here the inner loop basically finds a min value of the remaining subset. This progressively fills the array in the sorted order.The number of comparisons is bound by n^2/2 vs n^2 of TFA. |
|
The one in TFA isn't, for one crucial reason: the comparison is the other way around... And yet, it sorts.