Open
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
|
Collaborator
Author
🎤💬👥 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



🗒️ 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