shellsort

Fastest gap sequence for shell sort?

。_饼干妹妹 提交于 2021-02-07 11:17:23
问题 According to Marcin Ciura's Optimal (best known) sequence of increments for shell sort algorithm, the best sequence for shellsort is 1, 4, 10, 23, 57, 132, 301, 701..., but how can I generate such a sequence? In Marcin Ciura's paper, he said: Both Knuth’s and Hibbard’s sequences are relatively bad, because they are defined by simple linear recurrences. but most algorithm books I found tend to use Knuth’s sequence: k = 3k + 1, because it's easy to generate. What's your way of generating a

Fastest gap sequence for shell sort?

杀马特。学长 韩版系。学妹 提交于 2021-02-07 11:15:22
问题 According to Marcin Ciura's Optimal (best known) sequence of increments for shell sort algorithm, the best sequence for shellsort is 1, 4, 10, 23, 57, 132, 301, 701..., but how can I generate such a sequence? In Marcin Ciura's paper, he said: Both Knuth’s and Hibbard’s sequences are relatively bad, because they are defined by simple linear recurrences. but most algorithm books I found tend to use Knuth’s sequence: k = 3k + 1, because it's easy to generate. What's your way of generating a

What is the formula to get the number of passes in a shell sort?

我怕爱的太早我们不能终老 提交于 2020-07-10 08:58:05
问题 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

Shell sort Java example

☆樱花仙子☆ 提交于 2019-12-28 16:11:27
问题 Can anyone give me example about shell sort? I'm a new person in here who must learn about shell sort, but first I must find a Java shell sort example. I found one example in Google but it's too difficult. 回答1: Here, this code is very simple : /** * Shellsort, using Shell’s (poor) increments. * @param a an array of Comparable items. */ public static <T extends Comparable<? super T>> void shellsort( T [ ] a ) { int j; for( int gap = a.length / 2; gap > 0; gap /= 2 ) { for( int i = gap; i < a

Shell-sort algorithm variations in Java

好久不见. 提交于 2019-12-20 01:41:41
问题 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

Shellsorting an array from an input file

老子叫甜甜 提交于 2019-12-12 01:48:31
问题 The full project is to take data in from a file which is a text file containing a list of all 201 countries and their respective rates of internet use in alphabetical order. Here is an example Afghanistan 7 Albania 63 Algeria 20 Andorra 97 Angola 23 ... With this we have to Shellsort (specifically) the data numerically. I have successfully done this but I only am outputting a list of the percentages, where as I need the countries listed as well. Here is my code: import java.io.*; import java

How to choose the lengths of my sub sequences for a shell sort?

别等时光非礼了梦想. 提交于 2019-12-11 16:43:08
问题 Let's assume we have a sequence a_i of length n and we want to sort it using shell sort. To do so, we would choose sub sequences of out a_i's of length k_i. I'm now wondering how to choose those k_i's. You usually see that if n=16 we would choose k_1=8, k_2=4, k_3=2, k_4=1. So we would pair-wise compare the number's for each k_i and at the end use insertionSort to finish our sorting. The idea of first sorting sub sequences of length k_i is to "pre-sort" the sequence for the insertionSort.

Shell-sort algorithm variations in Java

北战南征 提交于 2019-12-01 20:54:45
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

Shell sort Java example

走远了吗. 提交于 2019-11-28 10:28:50
Can anyone give me example about shell sort? I'm a new person in here who must learn about shell sort, but first I must find a Java shell sort example. I found one example in Google but it's too difficult. Have you tried reading the wikipedia article first here ? It provides a pretty good basics with illustration and examples. Thereafter you might like to check out some java applets & animations depicting this sorting process here . Hopefully, after that, you might find the java code here , for example, far more readable. Hope it helps. Adelin Here, this code is very simple : /** * Shellsort,

Time complexity for Shell sort?

和自甴很熟 提交于 2019-11-27 03:33:41
问题 First, here's my Shell sort code (using Java): public char[] shellSort(char[] chars) { int n = chars.length; int increment = n / 2; while(increment > 0) { int last = increment; while(last < n) { int current = last - increment; while(current >= 0) { if(chars[current] > chars[current + increment]) { //swap char tmp = chars[current]; chars[current] = chars[current + increment]; chars[current + increment] = tmp; current -= increment; } else { break; } } last++; } increment /= 2; } return chars; }