-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
timsort #959
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
Comments
Hello, After some play with the code I reached the following conclusion:
Lines 56-62.
Lines 51-54. If you put the if clause with the break statement last, the program may add some elements to the new_run list twice. This happens as new_run initializes to [lst[0]] and it may happen that it adds some elements twice to different runs. In general, if you rely on the next loop iteration to add the previous element into a new_run list, it must do it explicitly ( if new_run==[]), which would mean another conditional. Right now, you will not lose an element if and only if the next iterated element is also smaller than the one before him :
Lines 56-64. Hope this helps. |
The previous algorithm was skipping numbers, according to issue TheAlgorithms#959, and my own tests. The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.
Update tim_sort.py The previous algorithm was skipping numbers, according to issue TheAlgorithms#959, and my own tests. The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement.
Can this issue be closed? |
* Update tim_sort.py Update tim_sort.py The previous algorithm was skipping numbers, according to issue #959, and my own tests. The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement. * Update tim_sort.py
* Update tim_sort.py Update tim_sort.py The previous algorithm was skipping numbers, according to issue TheAlgorithms#959, and my own tests. The version I am applying uses a while loop, which works correctly and is easier to compute, as there is no break statement. * Update tim_sort.py
When I used [2, 4, 5, 3, 1] to test, it just returned [1, 2, 4, 5]
The text was updated successfully, but these errors were encountered: