I'm referring to the original (Donald Shell's) algorithm. I'm trying to make a subjective sort based on shell sort. I already made all the logic, where it is exactly the same as the shell sort, but instead of the computer calculate what is greater, the user determines subjectively what is greater. But I would like to display a percentage or something to the user know how far in the sorting it is already. That's why I want to find a way to know it.

What is the formula to get the number of passes in a shell sort? I noticed it the number is not fixed, so what would be the minimum and maximum? N and N^2? Or maybe if you have an idea of how it is the best way to display the progress of the sorting, I will really appreciate it.

PS: It is not about the number of comparisons! Also not about time complexity. My question is about the number of passes in the array.

I did this formula displaying it by color. But it doesn't work with the right range.

```
List<Color> colors = [
Color(0xFFFF0000),//red
Color(0xFFFF5500),
Color(0xFFFFAA00),
Color(0xFFFFFF00),//yellow
Color(0xFFAAFF00),
Color(0xFF00FF00),
Color(0xFF00FF00),//green
];
[...]
style: TextStyle(
color: colors[(((pass - 1) * (colors.length - 1)) /
sqrt(a.length).ceil())
.floor()]),
[...]
```

asked on Stack Overflow Jun 18, 2020 by Hyung Tae Carapeto Figur • edited Jun 18, 2020 by Hyung Tae Carapeto Figur

Because one pass is the application of one element of the gap sequence, the number of passes depends on the used gap sequence.

If you use Shell's original gap sequence of powers of two, the number of passes is approximately the binary logarithms of the input size.

You can read more about other proposed gap sequences in the wikipedia article on Shell Sort: https://en.wikipedia.org/wiki/Shellsort

answered on Stack Overflow Jun 18, 2020 by Peter G.

User contributions licensed under CC BY-SA 3.0