Skip to content

Optimize Insertion Sort, update tests, & correct comments#617

Merged
trekhleb merged 2 commits into
trekhleb:mergefrom
austintheriot:insertion-sort
Jan 3, 2021
Merged

Optimize Insertion Sort, update tests, & correct comments#617
trekhleb merged 2 commits into
trekhleb:mergefrom
austintheriot:insertion-sort

Conversation

@austintheriot

Copy link
Copy Markdown
Contributor

Insertion Sort Clean Up

Algorithm Change

The existing insertion sort implementation began by iterating from
0 until the end of the array, but it is only necessary to
iterate from 1 until the end of the array, since at the
0th index, there is nothing to compare to the left of
the element.

I also corrected the grammar/wording of the comments.

Test Change

In order to complete this change, I also had to update the tests
to reflect the fact that the algorithm visits each index 1 less
time.

Diagnostics

Passed all tests and linting.

The existing insertion sort implementation began by iterating from
0 until the end of the array, but it is only necessary to
iterate from 1 until the end of the array, since at the
0th index, there is nothing to compare to the left of
the element.

In order to complete this change, I also had to update the tests
to reflect the fact that the algorithm visits each index 1 less
time.

Finally, I corrected the grammar/wording of the comments.
@austintheriot austintheriot changed the title optimized for loop, updated tests, & corrected comments Optimized for loop, updated tests, & corrected comments Dec 28, 2020
@austintheriot austintheriot changed the title Optimized for loop, updated tests, & corrected comments Optimize Insertion Sort, update tests, & correct comments Dec 28, 2020
@trekhleb

trekhleb commented Jan 3, 2021

Copy link
Copy Markdown
Owner

Thanks @austintheriot

@trekhleb trekhleb changed the base branch from master to merge January 3, 2021 09:25
@trekhleb trekhleb merged commit cf61af5 into trekhleb:merge Jan 3, 2021
@austintheriot austintheriot deleted the insertion-sort branch January 3, 2021 13:12
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