From 90a5e8405147a1e6729a2d7c157b0f32e4404017 Mon Sep 17 00:00:00 2001 From: "Vimal.V" <95672304+vimalvijenthiran@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:32:06 +0530 Subject: [PATCH 1/2] 3-insertsort.MD --- 2-algorithms/3-python/3-insertsort.MD | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 2-algorithms/3-python/3-insertsort.MD diff --git a/2-algorithms/3-python/3-insertsort.MD b/2-algorithms/3-python/3-insertsort.MD new file mode 100644 index 0000000..852205f --- /dev/null +++ b/2-algorithms/3-python/3-insertsort.MD @@ -0,0 +1,28 @@ +#definition +Insertion Sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, it has advantages in simplicity and is often used for small datasets. The algorithm is based on the idea of dividing the array into a sorted and an unsorted region. + +def insertion_sort(arr): + # Traverse through 1 to len(arr) + for i in range(1, len(arr)): + key = arr[i] + + # Move elements of arr[0..i-1] that are greater than key + # to one position ahead of their current position + j = i - 1 + while j >= 0 and key < arr[j]: + arr[j + 1] = arr[j] + j -= 1 + + arr[j + 1] = key + +# Example usage: +my_list = [64, 34, 25, 12, 22, 11, 90] + +print("Original List:") +print(my_list) + +# Applying Insertion Sort +insertion_sort(my_list) + +print("Sorted List:") +print(my_list) From 92452d218b5a914069a7d91c214bff0081d8721e Mon Sep 17 00:00:00 2001 From: Abishethvarman V <57715922+Abishethvarman@users.noreply.github.com> Date: Thu, 19 Oct 2023 01:18:13 +0530 Subject: [PATCH 2/2] Update and rename 3-insertsort.MD to 3-insertion-sort.MD --- .../3-python/{3-insertsort.MD => 3-insertion-sort.MD} | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) rename 2-algorithms/3-python/{3-insertsort.MD => 3-insertion-sort.MD} (93%) diff --git a/2-algorithms/3-python/3-insertsort.MD b/2-algorithms/3-python/3-insertion-sort.MD similarity index 93% rename from 2-algorithms/3-python/3-insertsort.MD rename to 2-algorithms/3-python/3-insertion-sort.MD index 852205f..fc85667 100644 --- a/2-algorithms/3-python/3-insertsort.MD +++ b/2-algorithms/3-python/3-insertion-sort.MD @@ -1,6 +1,10 @@ -#definition +# Insertion Sort in Python + +## definition Insertion Sort is a simple sorting algorithm that builds the final sorted array one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. However, it has advantages in simplicity and is often used for small datasets. The algorithm is based on the idea of dividing the array into a sorted and an unsorted region. + +## code level explantion def insertion_sort(arr): # Traverse through 1 to len(arr) for i in range(1, len(arr)):