Is there a way to calculate the starting point of a for loop and the adjustments to it. The original loop has these conditions
for( int gap = a.length / 2; gap > 0; gap /= 2 )
I adjusted it to set the conditions of the Hibbard's Shell Sort and got this
for( int gap = (int) Math.pow(2, a.length); gap > 0; gap /= 2 )
It works slightly better and might even be right, but I want to work with the more advanced shell sorts from here.
http://en.wikipedia.org/wiki/Shellsort#Gap_sequences
How could I turn (3^k - 1)/2 not greater than the ceiling of n/3 into a for loop condition?
The "k" value is the element of the sequence. So your for loop would probably look something like:
for (int k = 0; (Math.pow(3, k) - 1) / 2 <= Math.ceil(n / 3); k++) {
int gap = (int) ((Math.pow(3, k) - 1) / 2);
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With