Skip to content

Conversation

@dimitrijjedich
Copy link
Collaborator

🗒️ 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-while loop, 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 of value = 3×value_last+1 was used a suggested in this wikipedia article

@dimitrijjedich dimitrijjedich self-assigned this Dec 21, 2024
@sonarqubecloud
Copy link

@dimitrijjedich
Copy link
Collaborator Author

🎤💬👥 Discussion

Even 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants