|
Home
Download
Screenshots
Adding your sorts
Algorithms
-Bubble Sort
-Comb Sort
-Gnome Sort
-Heap Sort
-Insertion Sort
-Merge Sort
-Odd/Even Sort
-Quick Sort
-Quick Sort with Bubble Sort
-Radix Sort
-Rob (Random) Sort
-Selection Sort
-Shaker Sort
-Shear Sort
-Shell Sort
Donation:
|
Comb Sort
Description:
The Comb Sort, a type of Shell Sort, is a "diminishing increment sort."
Basically, it Insertion Sorts the elements of the list (L) that are Y
elements apart (comparing L[x] with L[x+Y]). Y, over the
iterations, decreases by some amount. The algorithm shown here
uses a formula that has been shown to be efficient.
This is one of the most efficient of the N2 sorting
algorithms. The reason for this is that the Insertion Sort becomes
more efficient if the list is already close to being sorted. Thus,
by sorting parts of the array first, the Insertion Sort is made
gradually more efficient.
Efficiency: O(N2)
Source:
public class CombSort: SortMethod
{
public override void sort(int[] list)
{
int interval=list.Length;
while(interval>0)
{
for(int x=0;x<list.Length;x+=interval)
{
int y=x;
while(y-interval>0&&list[y]<list[y-interval])
{
NumIterations++;
NumComparisons++;
pause(y,y-interval);
swap(list,y,y-interval);
y-=interval;
}
}
interval=(10*interval+3)/13;
}
}
public override string ToString()
{
return "Comb Sort";
}
} |
|