Skip to content

Commit 322eaa6

Browse files
committed
Insertions code comment updated, README file updated and added in TOC
1 parent 69bd4ce commit 322eaa6

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- [Sorting](./Sorting/)
3131
- Selection Sort
3232
- [Bubble Sort](./Sorting/Bubble%20Sort)
33-
- Insertion Sort
33+
- [Insertion Sort](./Sorting/Insertion%20Sort)
3434
- Merge Sort
3535
- Quick Sort
3636
- Bucket Sort

Sorting/Insertion Sort/Insertion.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
public class Insertion
1+
/* Insertion sort implementation in Java */
2+
3+
public class Insertion
24
{
35
//Following function will sort the array in Increasing (ascending) order
46
void sort(int arr[])

Sorting/Insertion Sort/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
**Insertion sort** does exactly what you would expect: it inserts each element of the array into its proper position, leaving progressively larger stretches of the array sorted. What this means in practice is that the sort iterates down an array, and the part of the array already covered is in order; then, the current element of the array is inserted into the proper position at the head of the array, and the rest of the elements are moved down, using the space just vacated by the element inserted as the final space.
44

5+
56
![Insertion Sort](insertion_sort.jpg)
67

78

8-
#####A visualization on Insertion Sort
9+
#### A visualization on Insertion Sort
910
![Insertion sort demonstration](https://upload.wikimedia.org/wikipedia/commons/0/0f/Insertion-sort-example-300px.gif)
1011

1112

12-
####Complexity Analysis
13-
- Worst Case - О(n<sup>2</sup>) comparisons, swaps
14-
- Average Case - О(n<sup>2</sup>) comparisons, swaps
15-
- Best Case - O(n) comparisons, O(1) swaps
13+
#### Complexity Analysis
14+
- Worst Case - О(n<sup>2</sup>)
15+
- Average Case - О(n<sup>2</sup>)
16+
- Best Case - O(n)
17+
1618
### More on this topic
17-
- https://en.wikipedia.org/wiki/Insertion_sort
18-
- http://quiz.geeksforgeeks.org/insertion-sort/
19-
- https://www.topcoder.com/community/data-science/data-science-tutorials/sorting/
19+
- [Insertion Sort - WikiPedia](https://en.wikipedia.org/wiki/Insertion_sort)
20+
- [Insertion Sort - geeksforgeeks](http://quiz.geeksforgeeks.org/insertion-sort/)

0 commit comments

Comments
 (0)