Skip to content
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

Added ShakerSort with tests #98

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Kirill99M
Copy link

@Kirill99M Kirill99M commented Jun 6, 2023

Added shaker sort

Sorting by mixing, also known as cocktail sort or shaker sort, is a variation of bubble sort that works by sorting the elements in both directions. Like bubble sort, sorting by mixing compares adjacent elements in the array and swaps them if they are in the wrong order. However, instead of only moving in one direction, sorting by mixing alternates moving from left to right and then from right to left through the array. This allows elements to "bubble up" or "bubble down" as needed in both directions, allowing for faster sorting in certain cases.

To begin, the first pass starts at the first element in the array and moves to the last element, swapping any adjacent elements that are in the wrong order. Then, the second pass starts at the last element in the array and moves to the first element, swapping any adjacent elements that are in the wrong order. These passes continue until no more swaps are made, indicating that the array is fully sorted.

Sorting by mixing is similar to bubble sort in terms of its simplicity and ease of implementation, but it can be more efficient in certain cases because it allows elements to move in both directions. However, like bubble sort, sorting by mixing has a worst-case time complexity of O(n^2), making it less efficient than more advanced sorting algorithms for larger arrays.

Copy link

@lkant8 lkant8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working currectoly

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