|
1 | | -/* |
2 | | -Wikipedia says: Comb sort improves on bubble sort. |
3 | | -
|
4 | | -The basic idea is to eliminate turtles, or small values |
5 | | -near the end of the list, since in a bubble sort these slow the sorting |
6 | | -down tremendously. Rabbits, large values around the beginning of the list, |
7 | | -do not pose a problem in bubble sort. |
8 | | -
|
9 | | -In bubble sort, when any two elements are compared, they always have a |
10 | | -gap (distance from each other) of 1. The basic idea of comb sort is |
11 | | -that the gap can be much more than 1. The inner loop of bubble sort, |
12 | | -which does the actual swap, is modified such that gap between swapped |
13 | | -elements goes down (for each iteration of outer loop) in steps of |
14 | | -a "shrink factor" k: [ n/k, n/k2, n/k3, ..., 1 ]. |
15 | | -
|
16 | | -*/ |
| 1 | +/** |
| 2 | + * Comb sort improves on bubble sort. |
| 3 | + * |
| 4 | + * The basic idea is to eliminate turtles, or small values |
| 5 | + * near the end of the list, since in a bubble sort these slow the sorting |
| 6 | + * down tremendously. Rabbits, large values around the beginning of the list, |
| 7 | + * do not pose a problem in bubble sort. |
| 8 | + * |
| 9 | + * In bubble sort, when any two elements are compared, they always have a |
| 10 | + * gap (distance from each other) of 1. The basic idea of comb sort is |
| 11 | + * that the gap can be much more than 1. The inner loop of bubble sort, |
| 12 | + * which does the actual swap, is modified such that gap between swapped |
| 13 | + * elements goes down (for each iteration of outer loop) in steps of |
| 14 | + * a "shrink factor" k: [ n/k, n/k2, n/k3, ..., 1 ]. |
| 15 | + */ |
17 | 16 |
|
18 | 17 | function combSort (list) { |
19 | 18 | if (list.length === 0) { |
|
0 commit comments