From 4377dc8437ca3c42e694ed75fb2f50aa424f3bb6 Mon Sep 17 00:00:00 2001 From: Anurag M <56573388+anuragmuxui@users.noreply.github.com> Date: Thu, 2 Oct 2025 12:57:50 +0530 Subject: [PATCH 1/3] Bubble sort --- Python/sorting/bubble_sort.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Python/sorting/bubble_sort.py diff --git a/Python/sorting/bubble_sort.py b/Python/sorting/bubble_sort.py new file mode 100644 index 0000000..a88d33d --- /dev/null +++ b/Python/sorting/bubble_sort.py @@ -0,0 +1,14 @@ +from collections import Counter + +def bubble_sort(arr, freq): + n = len(arr) + for i in range(n): + for j in range(0, n-i-1): + if (freq[arr[j]], -arr[j]) < (freq[arr[j+1]], -arr[j+1]): + arr[j], arr[j+1] = arr[j+1], arr[j] + +if __name__ == "__main__": + arr = [4,6,2,4,3,2,2,6] + freq = Counter(arr) + bubble_sort(arr,freq) + print(arr) From 0850f8bad47c554f815d6918009e13ea4d8808c4 Mon Sep 17 00:00:00 2001 From: Anurag M <56573388+anuragmuxui@users.noreply.github.com> Date: Thu, 2 Oct 2025 13:01:29 +0530 Subject: [PATCH 2/3] Add selection sort with frequency-based sorting Implement selection sort algorithm using frequency. --- Python/sorting/selection_sort.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Python/sorting/selection_sort.py diff --git a/Python/sorting/selection_sort.py b/Python/sorting/selection_sort.py new file mode 100644 index 0000000..bd27b63 --- /dev/null +++ b/Python/sorting/selection_sort.py @@ -0,0 +1,16 @@ +from collections import Counter + +def selection_sort(arr, freq): + n = len(arr) + for i in range(n): + max_idx = i + for j in range(i+1, n): + if (freq[arr[j]], -arr[j]) > (freq[arr[max_idx]], -arr[max_idx]): + max_idx = j + arr[i], arr[max_idx] = arr[max_idx], arr[i] + +if __name__ == "__main__": + arr = [4,6,2,4,3,2,2,6] + freq = Counter(arr) + selection_sort(arr,freq) + print(arr) From 439e7c549add0225feac407081279f689f0be1c7 Mon Sep 17 00:00:00 2001 From: Anurag M <56573388+anuragmuxui@users.noreply.github.com> Date: Thu, 2 Oct 2025 13:06:22 +0530 Subject: [PATCH 3/3] Fix print statement indentation in shell_sort.py --- Python/sorting/shell_sort.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Python/sorting/shell_sort.py diff --git a/Python/sorting/shell_sort.py b/Python/sorting/shell_sort.py new file mode 100644 index 0000000..48812d7 --- /dev/null +++ b/Python/sorting/shell_sort.py @@ -0,0 +1,20 @@ +from collections import Counter + +def shell_sort(arr, freq): + n=len(arr) + gap=n//2 + while gap>0: + for i in range(gap,n): + temp=arr[i] + j=i + while j>=gap and (freq[arr[j-gap]],-arr[j-gap])<(freq[temp],-temp): + arr[j]=arr[j-gap] + j-=gap + arr[j]=temp + gap//=2 + +if __name__=="__main__": + arr=[4,6,2,4,3,2,2,6] + freq=Counter(arr) + shell_sort(arr,freq) + print(arr)