-
Notifications
You must be signed in to change notification settings - Fork 0
Shell Sort #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Shell Sort #18
Conversation
starting at the second element of the column and going over all the elements of the columns, sorting them this way
effectively approaching the basic insertion sort but with a more sorted array
|
🎤💬👥 DiscussionEven though Donald Lewis Shell deserves credit for coming up with this implementation, this algorithm is basicly just an improvement of the insertion sort. With this fact i am not sure, if this deserves its own class or should be a variant of the insertionsort. Let me hear what you think about this |



🗒️ General
The base concept of Shell Sort is the insertion sort on an parts of an array with varying and decreasing gaps to make the sorting process more efficient. Starting with a large interval and gradually reducing it, this approach achieving a quicker sorting process because the insertion sort is run in it's base implementation at the end, the array is already in some form of order.
💡 Idea
In Shell Sort, a step sequence is used, which is based on the array length, to compare elements at different intervals. The algorithm starts with a large gap and reduces it in each iteration, refining the sorting process. The process continues until the gap is reduced to 1, which is the basic Insertion Sort as implemented in #1 and later extended in #5.
🤔 Details
The
stepSequence()method calculates the next value for the interval based on the current one. If the methods is just starting out, the lenght of the array is used for comparison. The main logic is to compare adjacent elements and swap them if they are in the wrong order. These comparisons are performed within a nested loop system: outer loops control the step sequence, while inner loops traverse the array to compare and swap elements.⏩ Implementation
The array is processed based on its length and step sequence in a
do-whileloop, which terminates after the last run of the basic implementation of the insertion sort and is identified by a step sequence of 1 and determines the end of the sorting.The
stepSequence()method calculates the next step sequences. Initially the algorithm was used with the sequence of 2 to the power of step. Here a different approach ofvalue = 3×value_last+1was used a suggested in this wikipedia article