diff --git a/algorithms/Sorting/1-IntroToTutorialChallenges/ProblemStatement/tutorial-intro-English.pdf b/algorithms/Sorting/1-IntroToTutorialChallenges/ProblemStatement/tutorial-intro-English.pdf new file mode 100644 index 0000000..d6ec1ef Binary files /dev/null and b/algorithms/Sorting/1-IntroToTutorialChallenges/ProblemStatement/tutorial-intro-English.pdf differ diff --git a/algorithms/Sorting/1-IntroToTutorialChallenges/Solutions/python.py b/algorithms/Sorting/1-IntroToTutorialChallenges/Solutions/python.py new file mode 100644 index 0000000..0ffeff2 --- /dev/null +++ b/algorithms/Sorting/1-IntroToTutorialChallenges/Solutions/python.py @@ -0,0 +1,13 @@ +#!/bin/python3 + +import sys + +def introTutorial(V, arr): + return(arr.index(V)) + +if __name__ == "__main__": + V = int(input().strip()) + n = int(input().strip()) + arr = list(map(int, input().strip().split(' '))) + result = introTutorial(V, arr) + print(result) diff --git a/algorithms/Sorting/2-InsertionSortPart1/ProblemStatement/insertionsort1-English.pdf b/algorithms/Sorting/2-InsertionSortPart1/ProblemStatement/insertionsort1-English.pdf new file mode 100644 index 0000000..c4c1e1d Binary files /dev/null and b/algorithms/Sorting/2-InsertionSortPart1/ProblemStatement/insertionsort1-English.pdf differ diff --git a/algorithms/Sorting/2-InsertionSortPart1/Solutions/python.py b/algorithms/Sorting/2-InsertionSortPart1/Solutions/python.py new file mode 100644 index 0000000..926bf68 --- /dev/null +++ b/algorithms/Sorting/2-InsertionSortPart1/Solutions/python.py @@ -0,0 +1,30 @@ +#!/bin/python3 + +import sys + +def insertionSort1(n, arr): + last = arr[-1] + last = arr[-1] + x = 0 + while arr[n-(n+2) - x] > last: + arr[-1-x] = arr[n-(n+2) - x] + print (' '.join(str(y) for y in arr)) + if x+2 == len(arr): + arr[n-(n+2) - x] = last + break + else: + x += 1 + + if arr[n-(n+2) - x] < last: + arr[-x-1] = last + print (' '.join(str(y) for y in arr)) + else: + print (' '.join(str(y) for y in arr)) + + + + +if __name__ == "__main__": + n = int(input().strip()) + arr = list(map(int, input().strip().split(' '))) + insertionSort1(n, arr) diff --git a/algorithms/Sorting/3-InsertionSortPart2/ProblemStatement/insertionsort2-English.pdf b/algorithms/Sorting/3-InsertionSortPart2/ProblemStatement/insertionsort2-English.pdf new file mode 100644 index 0000000..8e20405 Binary files /dev/null and b/algorithms/Sorting/3-InsertionSortPart2/ProblemStatement/insertionsort2-English.pdf differ diff --git a/algorithms/Sorting/3-InsertionSortPart2/Solutions/python.py b/algorithms/Sorting/3-InsertionSortPart2/Solutions/python.py new file mode 100644 index 0000000..1779fc9 --- /dev/null +++ b/algorithms/Sorting/3-InsertionSortPart2/Solutions/python.py @@ -0,0 +1,21 @@ +#!/bin/python3 + +import sys + +def insertionSort2(n, l): + for i in range(1, len(l)): + j = i-1 + key = l[i] + while (j >= 0) and (l[j] > key): + l[j+1],l[j] = l[j],l[j+1] + j -= 1 + l[j+1] = key + print(" ".join(map(str,l))) + + + + +if __name__ == "__main__": + n = int(input().strip()) + arr = list(map(int, input().strip().split(' '))) + insertionSort2(n, arr) diff --git a/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/ProblemStatement/correctness-invariant-English.pdf b/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/ProblemStatement/correctness-invariant-English.pdf new file mode 100644 index 0000000..3abd150 Binary files /dev/null and b/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/ProblemStatement/correctness-invariant-English.pdf differ diff --git a/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/Solutions/python.py b/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/Solutions/python.py new file mode 100644 index 0000000..7523096 --- /dev/null +++ b/algorithms/Sorting/4-CorrectnessAndTheLoopInvariant/Solutions/python.py @@ -0,0 +1,14 @@ +def insertion_sort(l): + for i in range(1, len(l)): + j = i-1 + key = l[i] + while (j >= 0) and (l[j] > key): + l[j+1] = l[j] + j -= 1 + l[j+1] = key + + +m = int(input().strip()) +ar = [int(i) for i in input().strip().split()] +insertion_sort(ar) +print(" ".join(map(str,ar))) diff --git a/algorithms/Sorting/5-QuickSort1-Partition/ProblemStatement/quicksort1-English.pdf b/algorithms/Sorting/5-QuickSort1-Partition/ProblemStatement/quicksort1-English.pdf new file mode 100644 index 0000000..472d7b0 Binary files /dev/null and b/algorithms/Sorting/5-QuickSort1-Partition/ProblemStatement/quicksort1-English.pdf differ diff --git a/algorithms/Sorting/5-QuickSort1-Partition/Solutions/python.py b/algorithms/Sorting/5-QuickSort1-Partition/Solutions/python.py new file mode 100644 index 0000000..5d1c978 --- /dev/null +++ b/algorithms/Sorting/5-QuickSort1-Partition/Solutions/python.py @@ -0,0 +1,31 @@ +#!/bin/python3 + +import sys + +def quickSort(arr): + left = [] + equal = [] + right = [] + pivot = arr[0] + for x in arr: + if x == pivot: + equal.append(x) + elif x > pivot: + right.append(x) + else: + left.append(x) + + arr[:] =[] + arr += left + arr += equal + arr += right + return arr + + +if __name__ == "__main__": + n = int(input().strip()) + arr = list(map(int, input().strip().split(' '))) + result = quickSort(arr) + print (" ".join(map(str, result))) + +