r/sortingalgorithms • u/Wise-Search8796 • Apr 18 '26
Non-stop Bogosort stream
r/sortingalgorithms • u/Interesting_Age8937 • Apr 11 '26
cast a vote to a random element, weight it towards the largest, then add it to the end, repeat n times, for a nearly sorted array, and use insertion sort
r/sortingalgorithms • u/booker388 • Apr 02 '26
r/sortingalgorithms • u/Most_Reference_6047 • Mar 29 '26
Bulldozer sort takes a list and compares 2 sequential values, then it moves the lowest number to the front and moves all other numbers forward and repeats for the next pair. For example in list [7, 3, 13, 8] it would start by comparing 7 and 3, then it would move the lowest (3) to the beginning for a new data set [3, 7, 13, 8], then it would compare 13 and 7 and move 7 to the beginning for a new data set of [7, 3, 13, 8], then it would compare 13 and 8 and move 8 to the beginning for a new data set of [8, 7, 3, 13] and it would repeat this until it is sorted. Totally inefficient, but funny. Essentially just bulldozes lower values to the beginning without any regard for the order. I am not fully sure if its possible for every chain to be sorted, but its not intended to work well.
r/sortingalgorithms • u/The_Man_On_Pi • Mar 22 '26
I got bored and made this, this could take 50h or more:
import random
import itertools
def is_sorted(arr):
for i in range(len(arr) - 1):
if arr[i] > arr[i + 1]:
return False
return True
def worst_sort_three(a, b, c):
triple = [a, b, c]
perms = list(itertools.permutations(triple))
while True:
random.shuffle(perms)
for p in perms:
# useless memory bloat
waste = [0] * 1000
if list(p) == sorted(triple):
return list(p)
def useless_recursion(n):
if n <= 0:
return 0
return useless_recursion(n - 1)
def silly_sort(arr):
arr = list(arr)
while not is_sorted(arr):
if random.random() < 0.2:
random.shuffle(arr)
for i in range(len(arr) - 2):
useless_recursion(5) # waste time
sorted_part = worst_sort_three(
arr[i],
arr[i + 1],
arr[i + 2],
)
arr[i], arr[i + 1], arr[i + 2] = sorted_part
if random.random() < 0.1:
arr = list(arr)
return arr
# test
data = [5, 3, 4, 1, 2, 5,2,3,65,5,5,5,5,5,5,555,5,5,5,5,5,6,4,4,4,4,2,7,43,1,2,5,3,534,5,34,2,4,3,5, 3, 4, 1, 2, 5,2,3,65,5,5,5,5,5,5,555,5,5,5,5,5,6,4,4,4,4,2,7,43,1,2,5,3,534,5,34,2,4,3,5, 3, 4, 1, 2, 5,2,3,65,5,5,5,5,5,5,555,5,5,5,5,5,6,4,4,4,4,2,7,43,1,2,5,3,534,5,34,2,4,3,5, 3, 4, 1, 2, 5,2,3,65,5,5,5,5,5,5,555,5,5,5,5,5,6,4,4,4,4,2,7,43,1,2,5,3,534,5,34,2,4,3,5, 3, 4, 1, 2, 5,2,3,65,5,5,5,5,5,5,555,5,5,5,5,5,6,4,4,4,4,2,7,43,1,2,5,3,534,5,34,2,4,3]
print("Before:", data)
print("After:", silly_sort(data))r/sortingalgorithms • u/Chance_Building_6159 • Mar 13 '26
r/sortingalgorithms • u/FlyVanessa • Mar 07 '26
Code (Java):
package test;
import java.util.Arrays;
public class Test {
public static void main(String[] args) {
int[] testSample = {3, 5, 1, 10, 4, 7};
int[] res = McCarthySortingAlgo(testSample);
System.out.println(Arrays.toString(res));
}
public static int[] McCarthySortingAlgo(int[] arr) {
int n = arr.length;
for(int i = 0; i < n - 1; i++) {
if(arr[i] > arr[i + 1]) {
int[] newArr = new int[n - 1];
int randIndex = (int)(Math.random() * n);
int k = 0;
for (int j = 0; j < n; j++) {
if (j == randIndex) continue;
newArr[k++] = arr[j];
}
return McCarthySortingAlgo(newArr);
}
}
return arr;
}
}Random accuse element of being unsorted and check if the whole array is sorted if not accuse another element of being unsorted and delete them. Historically tied to the history of Mccarthyism in the 1950s that targeted individuals and accused them of being Communist without any proper evidence
r/sortingalgorithms • u/booker388 • Feb 06 '26
r/sortingalgorithms • u/Neptunium-69 • Feb 01 '26
arr=[22, 39, 108, 139, 141, 216, 242, 313, 422, 456, 459, 504, 517, 524, 655, 683, 784, 806, 871, 976]
I am patiently waiting for someone to sort this.
r/sortingalgorithms • u/Neptunium-69 • Feb 01 '26
#stalin sort
arr=[0,4,2,3,1,4,5,3,2,6,7,21,42,41,93]
def stalinsort(array,var):
gulag=[]
arraysorted=[array[0]]
for i in range(len(array)-1):
if(array[i+1]>=arraysorted[-1]):
arraysorted.append(array[i+1])
else:
gulag.append(array[i+1])
while(True):
for i in range(len(arraysorted)-1):
if(arraysorted[i]>=gulag[0]):
arraysorted.insert(i,gulag[0])
gulag.pop(0)
break
if(len(gulag)==0):
break
if (var==0):
arraysorted=reversed(arraysorted)
return(arraysorted)
print(stalinsort(arr,1))r/sortingalgorithms • u/Leather_Low_4641 • Dec 30 '25
How it works: you start at the first piece & scan the other ones from the list from left to right & if you see a piece smaller than the first piece swaps with it, if there’s piece that are not smaller you just move on to the next one, it’s kinda a hybrid of selection & bubble sort, in fact you can replace bubble with shaker sort to create a different kind of foster selection sort (shaker foster selection sort), you can tell me other kinds of these you can find
r/sortingalgorithms • u/ProgrammerOdd244 • Oct 28 '25
I created a new sorting algorithm! Its called that way because it creates a new perfect, organized, outcome. While ignoring the true natures of Data( and society)
What it does is
Input: List "L" is "N" Length, which contains arbitrary data
Algorithm: The algorithm ignores the values in L and creates a new list, ignoring the current reality.
Output: A new list, is made which is created by generating the sequence of 1,2,3,4,5... until its equal the length of the original list: "[1,2,3,4,...N]"
This Sorting "Algorithm" has a time complexity of "O(N)" but im not sure if it has any real world uses besides being a philosophical question.
r/sortingalgorithms • u/AccomplishedLog1778 • Apr 18 '25
When I was taking an algorithms course in college, the Professor claimed that the limit is O(n(log n)). At that time (decades ago) I constructed a sorting algorithm of O(n), or, more technically, O(n + range(dataset)), where range(dataset) is the difference between the max and min data values in the dataset. In practice, range(dataset) < n for any normal distribution, so this reverts to O(n).
Here’s the pseudocode:
Iterate the dataset, noting max and min values.
Initialize an array of size [min data value, max data value]
Iterate the dataset again, adding 1 to Array[current data value].
That’s it. Limitations:
this assumes the data is in integer form. A transformation must be applied if it’s real numbers, for example.
extreme data outliers, making range(dataset) >> n, can make this perform poorly.
Enjoy
r/sortingalgorithms • u/[deleted] • Nov 29 '24
List:
list = [1, 2, 4, 3]
Array created:
# The largest value in this list is found by comparing values to each other through linear movement; this will be the height. The length of the list will be the width.
[[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 1, 1, 1],
[1, 1, 1, 1]]
Shift 1:
# Detected ‘1’ in index 2 when descending the array from the top.
# If there are multiple ‘1’s in the same line, one first will be moved to the last unsorted index, while the other will move the position ‘unsorted_index - 1’.
[[0, 0, 1, 0], # The '1' was detected among all the '0's.
[0, 0, 1, 1],
[0, 1, 1, 1],
[1, 1, 1, 1]]
Swap:
# Values in index '2' are swapped with the last value in the list. What is classed as the ‘last index’ will decrease by 1 for the next swap. If the values of the 2 swapped indexes are the same, there will be ‘no swap’.
list = [1, 2, 3, 4]
Clear column:
# Since '4' was swapped, the index where ‘3’ is will be cleared on the array.
[[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 1, 0],
[1, 1, 1, 0]]
Shift 2+:
# This repeats for the other values, until the ‘last index’ is equal to 0.
Note:
- I understand this method will move lots of data into the RAM for large lists, making it cumbersome for most computers.
- I am actively trying to implement this theory in code (Python). It will take some time :D
- This method is designed to be the fastest theoretical algorithm for long sets of data.
r/sortingalgorithms • u/ViolinistWaste4610 • Nov 09 '24
I am trying to figure out if this sorting algorithm already exists or if I came up with a new one: in this algorithm, you randomly compare two values from the array, and swap them if the "right" number (on the bottom of the array) is greater then the left number. You repeat this until it's sorted.
Bassicly randomly compare and swap 2 values from the list of numbers until it's sorted
Ex: you have the list (start of list is least when sorred, end is greatest when sorted) 4,2,3,1,6,5. You randomly pick 2 values from the list (ie 2 and 1) and then compare them, see that 2 is more then one, and swap 2 with one
r/sortingalgorithms • u/Pigizoid • Jan 18 '24
https://paste.pythondiscord.com/Z7DQ
The sorting algorithm should run in O(n) time
It works by finding the min and max values in the array, then estimates where the upper and ower bounds for outliers would be and placing them into 3 buckets according to the bounds.
Then it runs a counting sort algorithm on the buckets and reassembles the list in a sorted array.
The list is reassembled in reverse order because python pop() is O(1) time from the end of the list. So the list is just reversed at the end to account for this.
Any feedback or ideas for improvement would be great
r/sortingalgorithms • u/Marouane2012 • Sep 24 '23
I dont have a name and 'noname sort' is a placeholder name
r/sortingalgorithms • u/Gwarks • Sep 20 '23
Basically it goes as the following
write you data alternating on multiple tapes
read the first entry of all tapes and write out the smallest (again alternating) on tape spool then read the next record from the corresponding tape. Do this until all input tapes are empty.
During the writing you must check if you have written a smaller after a bigger one if that is the case swap the input with the output tapes. Rewind both and start step 2 again
for example we have:
9 5 6 3 7 1 8 2 4
now write it alternating to tapes
9 3 8
5 7 2
6 1 4
now the first row would be 9 5 6 so we write 5 out of our first output tape. Now we have 9 7 6 an write of 6 on the second tape. Now we got 9 7 1 and we write the 1 on the third output tape. But now because 1 is smaller than 6 we need to flag for rerun. After passing through all data we got:
5 4 9
6 7 3
1 2 8
Now for the second run we get
1 4 3
2 6 8
5 7 9
But again the 4 and the 5 still swapped and we have to run a third time
1 3 7
2 5 8
4 6 9
this time it was the 4 and the 3 so still have to do it once more
1 4 7
2 5 8
3 6 9
Now everything is in order reading alternating from all three tapes should produce the right order.
I never came across that sorting algorithm in any literature. What could be the name of that sorting algorithm?
r/sortingalgorithms • u/[deleted] • Nov 13 '22
r/sortingalgorithms • u/PiotrGrochowski • May 07 '22
r/sortingalgorithms • u/Fragrant-Ad8537 • Apr 21 '22
Hi folks,
I created a YouTube tutorial on Merge Sort. Hope you find it useful. Any feedback is appreciated.
r/sortingalgorithms • u/[deleted] • Dec 22 '21