-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Improvement in CycleSort algorithm #194
Labels
Comments
hammadsaedi
changed the title
Bug in CycleSort algorithm
Improvement in CycleSort algorithm
Oct 3, 2023
hammadsaedi
added a commit
to hammadsaedi/30-seconds-of-java
that referenced
this issue
Oct 3, 2023
@iluwatar pls check this out :) |
github-project-automation
bot
moved this from In Progress
to Done
in Java Design Patterns project
Oct 14, 2023
iluwatar
pushed a commit
that referenced
this issue
Oct 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File: master/src/main/java/algorithm/CountingSortSnippet.java
Description:
The cycle sort algorithm has a bug in the following line:
The bug is that the condition
arr[i] < n
is not necessary. The algorithm should simply check if the element ati
is not in its correct position.Workaround:
To fix the bug, simply remove the condition
arr[i] < n
from the following line:The corrected line is:
Proposed fix:
I propose that we make the following change to the
cycleSort()
method:This change will fix the bug and make the algorithm more efficient.
The text was updated successfully, but these errors were encountered: