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 bogosort algorithem #147

Merged
merged 9 commits into from
Aug 9, 2023
Merged

added bogosort algorithem #147

merged 9 commits into from
Aug 9, 2023

Conversation

mendlero
Copy link
Contributor

@mendlero mendlero commented Aug 7, 2023

added bogosort algorithem

Copy link
Contributor

@appgurueu appgurueu left a comment

Choose a reason for hiding this comment

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

  • The Fisher-Yates shuffle and isSorted should get their own files (and tests); they are much more useful than bogosort. This will trivialize the bogosort.
  • Don't use var, use let and const instead.
  • The complexity analysis is wrong. The best case complexity is O(n), since a single isSorted check takes O(n). The (expected) average complexity is not "unbounded"; yes, it can in theory fail to find the correct permutation infinitely often, but the probability for that is 0: Each iteration has a probability of 1/n! of succeeding. You obtain an expected O(n!n) time complexity using the geometric distribution since each iteration takes O(n) time.
  • You need to add tests. Please try to do this without simply duplicating tests.

@mendlero
Copy link
Contributor Author

mendlero commented Aug 8, 2023

  • The Fisher-Yates shuffle and isSorted should get their own files (and tests); they are much more useful than bogosort. This will trivialize the bogosort.
  • Don't use var, use let and const instead.
  • The complexity analysis is wrong. The best case complexity is O(n), since a single isSorted check takes O(n). The (expected) average complexity is not "unbounded"; yes, it can in theory fail to find the correct permutation infinitely often, but the probability for that is 0: Each iteration has a probability of 1/n! of succeeding. You obtain an expected O(n!n) time complexity using the geometric distribution since each iteration takes O(n) time.
  • You need to add tests. Please try to do this without simply duplicating tests.

Thanks for reviewing so quickly, I refactored the code, added tests and change the time complexity in the latest commits.

@mendlero mendlero requested a review from appgurueu August 8, 2023 05:18
other/shuffle_array.ts Outdated Show resolved Hide resolved
sorts/bogo_sort.ts Outdated Show resolved Hide resolved
@raklaptudirm raklaptudirm merged commit a4c8d37 into TheAlgorithms:master Aug 9, 2023
2 checks passed
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.

3 participants