Improve insertion_sort docstring with complexity analysis#14875
Open
shreya-learn-explores wants to merge 4 commits into
Open
Improve insertion_sort docstring with complexity analysis#14875shreya-learn-explores wants to merge 4 commits into
shreya-learn-explores wants to merge 4 commits into
Conversation
for more information, see https://pre-commit.ci
zain-cs
approved these changes
Jun 29, 2026
zain-cs
left a comment
Contributor
There was a problem hiding this comment.
Reviewed both commits and the final diff.
Code correctness:
The complexity claims added to the docstring are accurate against the actual implementation:
- Best Case: O(n) — correct, since the inner while-loop exits immediately on an already-sorted run.
- Average/Worst Case: O(n²) — correct, confirmed by the shift-back behavior in the while-loop on reverse-sorted input.
- Space Complexity: O(1) — correct, sorting is done in place with no auxiliary collection.
CI status:
- Initial commit (7513a1b) had 2/5 checks passing.
- pre-commit.ci's auto-fix commit (9e3cd71) brought it to 4/5, resolving lint/formatting issues.
deploy_docsshows as skipped, which is expected behavior on PR branches (it only runs on merge to master).- build, sphinx/build_docs, and ruff all pass on the final commit.
Scope:
Documentation-only change (+8/−0), no logic touched, existing doctests unaffected.
LGTM — approving.
mindaugl
approved these changes
Jun 29, 2026
jordandunmire97-ai
approved these changes
Jun 29, 2026
jordandunmire97-ai
approved these changes
Jun 29, 2026
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
This pull request improves the docstring of the
insertion_sort()function insorts/insertion_sort.pyby adding time and space complexity analysis.Changes made:
This helps improve code readability and makes the algorithm easier to understand for beginners.
Fixes #14866
Checklist: