From 6f9a7ac8bd6ebf0c400fae555e84c430b743a180 Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 14:53:02 +0530 Subject: [PATCH 01/11] Create insertionsort.md --- snippets/insertionsort.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 snippets/insertionsort.md diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md new file mode 100644 index 000000000..aad066a0e --- /dev/null +++ b/snippets/insertionsort.md @@ -0,0 +1,19 @@ +### Insertion Sort + +```py +arr = [7,4,9,2,6,3] + +def insertionsort(arr): + + for i in range(1, len(arr)): + key = arr[i] + j = i-1 + while j>=0 and key < arr[j]: + arr[j+1] = arr[j] + j -= 1 + arr[j+1] = key + + +insertionsort(arr) +print('modified %s' %arr) # modified [2, 3, 4, 6, 7, 9] +``` From f550102a4317676cf828f8b072c5f2f8180e7b3f Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 15:01:33 +0530 Subject: [PATCH 02/11] Update insertionsort.md --- snippets/insertionsort.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md index aad066a0e..bc5f9747c 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertionsort.md @@ -1,6 +1,6 @@ ### Insertion Sort -```py +```python arr = [7,4,9,2,6,3] def insertionsort(arr): @@ -15,5 +15,5 @@ def insertionsort(arr): insertionsort(arr) -print('modified %s' %arr) # modified [2, 3, 4, 6, 7, 9] +print('Sorted %s' %arr) # sorted [2, 3, 4, 6, 7, 9] ``` From 4f4bce9c2e56fe2d6ced87b3a790199b7de67bfd Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 15:03:22 +0530 Subject: [PATCH 03/11] Update insertionsort.md --- snippets/insertionsort.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md index bc5f9747c..ce5a11ec1 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertionsort.md @@ -1,5 +1,23 @@ -### Insertion Sort +## Insertion Sort +## Implementation +```python +arr = [] # list to sort + + +def insertionsort(arr): + + for i in range(1, len(arr)): + key = arr[i] + j = i-1 + while j>=0 and key < arr[j]: + arr[j+1] = arr[j] + j -= 1 + arr[j+1] = key +``` + + +### Example ```python arr = [7,4,9,2,6,3] From a10e639139068f23651dc8fed8390c775c62a773 Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 15:05:38 +0530 Subject: [PATCH 04/11] Update insertionsort.md --- snippets/insertionsort.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md index ce5a11ec1..a18ecae40 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertionsort.md @@ -1,5 +1,8 @@ ## Insertion Sort +On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! + + ## Implementation ```python arr = [] # list to sort From 0217b426cb48364275d0dd8c98a3830283619bef Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Tue, 20 Feb 2018 15:07:03 +0530 Subject: [PATCH 05/11] Update insertionSort.md --- snippets/insertionsort.md | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/snippets/insertionsort.md b/snippets/insertionsort.md index a18ecae40..cbf6c2442 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertionsort.md @@ -1,13 +1,8 @@ -## Insertion Sort +### Insertion Sort On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! - -## Implementation ```python -arr = [] # list to sort - - def insertionsort(arr): for i in range(1, len(arr)): @@ -19,22 +14,8 @@ def insertionsort(arr): arr[j+1] = key ``` - -### Example ```python arr = [7,4,9,2,6,3] - -def insertionsort(arr): - - for i in range(1, len(arr)): - key = arr[i] - j = i-1 - while j>=0 and key < arr[j]: - arr[j+1] = arr[j] - j -= 1 - arr[j+1] = key - - insertionsort(arr) print('Sorted %s' %arr) # sorted [2, 3, 4, 6, 7, 9] ``` From 1b7e4c4b413e0235728f7173ecc651fa9d1e2d2b Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Tue, 20 Feb 2018 15:07:30 +0530 Subject: [PATCH 06/11] Update and rename insertionsort.md to insertion_sort.md --- snippets/{insertionsort.md => insertion_sort.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename snippets/{insertionsort.md => insertion_sort.md} (96%) diff --git a/snippets/insertionsort.md b/snippets/insertion_sort.md similarity index 96% rename from snippets/insertionsort.md rename to snippets/insertion_sort.md index cbf6c2442..6c6625272 100644 --- a/snippets/insertionsort.md +++ b/snippets/insertion_sort.md @@ -1,4 +1,4 @@ -### Insertion Sort +### insertion_sort On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! From dc76f610f8ddc877c21dd8237f337893cebaa11a Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 15:53:05 +0530 Subject: [PATCH 07/11] Update insertion_sort.md --- snippets/insertion_sort.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/snippets/insertion_sort.md b/snippets/insertion_sort.md index 6c6625272..f00e41ce9 100644 --- a/snippets/insertion_sort.md +++ b/snippets/insertion_sort.md @@ -1,4 +1,6 @@ -### insertion_sort +## insertion_sort + +### Insertion Sort Algorithm On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! From 8b53232db68f82c9ebe85da8203852206a80b175 Mon Sep 17 00:00:00 2001 From: Rohit Tanwar <31792358+kriadmin@users.noreply.github.com> Date: Tue, 20 Feb 2018 16:36:12 +0530 Subject: [PATCH 08/11] Update insertion_sort.md --- snippets/insertion_sort.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/snippets/insertion_sort.md b/snippets/insertion_sort.md index f00e41ce9..6c6625272 100644 --- a/snippets/insertion_sort.md +++ b/snippets/insertion_sort.md @@ -1,6 +1,4 @@ -## insertion_sort - -### Insertion Sort Algorithm +### insertion_sort On a very basic level, an insertion sort algorithm contains the logic of shifting around and inserting elements in order to sort an unordered list of any size. The way that it goes about inserting elements, however, is what makes insertion sort so very interesting! From f55ce6ce1c33dc7272ad20a9740929788878b4e1 Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 16:49:29 +0530 Subject: [PATCH 09/11] Update contributor_database --- contributor_database | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contributor_database b/contributor_database index 17e428769..d99366c01 100644 --- a/contributor_database +++ b/contributor_database @@ -21,4 +21,5 @@ palindrome:[Rohit Tanwar](@kriadmin) is_upper_case:[Rohit Tanwar](@kriadmin) is_lower_case:[Rohit Tanwar](@kriadmin) count_by:[Rohit Tanwar](@kriadmin) -difference_by:[Rohit Tanwar](@kriadmin) \ No newline at end of file +difference_by:[Rohit Tanwar](@kriadmin) +insertion_sort:[Meet Zaveri](@meetzaveri) From 709ca38efae5d563f135bd25eab2007fcac850f2 Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 16:49:48 +0530 Subject: [PATCH 10/11] Update tag_database --- tag_database | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tag_database b/tag_database index f8be5804e..4c4918959 100644 --- a/tag_database +++ b/tag_database @@ -21,4 +21,5 @@ palindrome:string is_upper_case:string is_lower_case:string count_by:list -difference_by:list \ No newline at end of file +difference_by:list +insertion_sort:list From 0b9b98a8fe762d65d2b56465ceb81da4ce5bee26 Mon Sep 17 00:00:00 2001 From: Meet Zaveri Date: Tue, 20 Feb 2018 16:52:06 +0530 Subject: [PATCH 11/11] Update contributor_database --- contributor_database | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contributor_database b/contributor_database index d99366c01..471bb5072 100644 --- a/contributor_database +++ b/contributor_database @@ -21,5 +21,6 @@ palindrome:[Rohit Tanwar](@kriadmin) is_upper_case:[Rohit Tanwar](@kriadmin) is_lower_case:[Rohit Tanwar](@kriadmin) count_by:[Rohit Tanwar](@kriadmin) -difference_by:[Rohit Tanwar](@kriadmin) insertion_sort:[Meet Zaveri](@meetzaveri) +difference_by:[Rohit Tanwar](@kriadmin) +