Skip to content

Commit

Permalink
Update 033-insertion-sort-python.md
Browse files Browse the repository at this point in the history
  • Loading branch information
rylim authored Oct 12, 2021
1 parent c780f43 commit 9a2c818
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion python/033-insertion-sort-python.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ while i < length(A)
end while
```

The general idea behind it is to iterate through the array from beginning to end and swaps each element from the current element to the beginning of the array if a "greater" prior element is found compare to the current element.
The general idea behind it is to iterate through the array from beginning to end and swaps each element from the current element to the beginning of the array if a "greater" prior element is found compare to the current element. It basically sorts "subsections" of the array repeatedly until the entire array is sorted.

## Python Implementation

Expand All @@ -46,6 +46,7 @@ def insertion_sort(array):
for i in range(1, len(array)):
j = i
while j > 0 and array[j - 1] > array[j]:
# swap the two array elements
temp = array[j - 1]
array[j - 1] = array[j]
array[j] = temp
Expand Down

0 comments on commit 9a2c818

Please sign in to comment.