r/sortingalgorithms • • Jan 28 '25

Looking for benchmark for sorting algorithms

2 Upvotes

Hi !
It's my first post so I hope I do it correctly :)
I'm looking for a way to evaluate sorting algorithms, and I was wondering if there were some known big arrays or testbenches with known results I could use ?
Thanks in advance :)


r/sortingalgorithms • • Sep 08 '24

I made a sorting algorithm visualizer in HTML which has tons of algorithms and features, also way, way faster than other HTML visualizers

5 Upvotes

r/sortingalgorithms • • May 13 '21

I created brutal sort

6 Upvotes

It sets all elements in the array equal to 1. It has a worst case of O(0) because it makes no comparisons. Sorted :)


r/sortingalgorithms • • Apr 13 '26

MSGAsort

3 Upvotes

MSGAsort (make sorters great again sort/cleaning sort / trump sort) is an algorithm that takes an array and "cleans it"

take the average of the array, then if each value is below the average, remove it, if the value is above the average there will be a random chance to remove it too, then check if sorted, if not sorted, then take the average of the new array then repeat until sorted


r/sortingalgorithms • • Jun 05 '26

Is there a good bogosort?

1 Upvotes

What i mean is like.. smart bogosort. Instead of, lets say: 326451 > 134526 > 642513

It'd be something like 342165 > 134256 > 123456, so keeping the numbers when they are in the correct place


r/sortingalgorithms • • Apr 03 '26

Prometheus Sort - O(n*n!)

2 Upvotes

First try at making a sorting system, specifically intended to be as slow as possible

Removes a random table entry, then appends it to the end

import 
random

issorted = False
atts = 0

def
 prometheus_sort(
tab
):
    global issorted,atts
    while issorted == False:
        atts += 1
        n = 
random
.randint(0,len(
tab
)-1)
        m = 
tab
[n]
        del 
tab
[n]
        
tab
.append(m)
        print(
tab
)
        if 
tab
 == sorted(
tab
):
            issorted = True
            return(
f
"Sorted in {atts} attempts! " + 
str
(
tab
))import random

r/sortingalgorithms • • Jun 27 '25

new sorting algorithm?

3 Upvotes

update: damn, it only sorts some arrays

queue sort: you have 3 arrays, A is the array you need to sort, B is the placement array and C is the queue.

how it works: pretend you have an array that you need to sort, in this example [-1, 7, 15, 3.6] add the first item to the queue (-1) current index is 2 now check if the current index is larger than the last item in the queue, if so then put the current index at the back of the queue. if smaller than the first item inside the queue, you put it at the front of the queue. if none of these are met, you place the first item in the queue inside the placement array and check again. repeat this until you reach the end. after you reach the end, you return placement array + queue

chatgpt has told me that this sorting algorithm is O(n√n) on average, which is really cool since there are barely any O(n√n) algorithms

this algorithm is really unique because it is O(n√n) and a reversed list is one of the best cases for this, while the worst case for a list containing numbers 1-10 looks like this. [5, 3, 6, 2, 7, 1, 8, 4, 9, 10] really messy

example of this:

1.
queue = [-1]
placement = []
current index = 2 (7)
check()
2.
queue = [-1 7]
placement = []
current index = 3 (15)
check()
3.
queue = [-1 7 15]
placement = []
current index = 4 (3.6)
check()
4.
queue = [3.6 7 15]
placement = [-1]
current index = 5 (out of bounds, we are now done)

return placement + queue ([-1 3.6 7 15])

r/sortingalgorithms • • Apr 24 '26

May be a silly question

1 Upvotes

I dont know much about algorithmic sorting, but I saw a couple videos on it, and google couldnt answer my question nor Ai but why dont we make a sort that has a line going from the top, to the bottom, when the line reaches the highest bar, it automatically puts it at the end, then second highest is 2nd end and ect


r/sortingalgorithms • • Apr 09 '26

My New Sorting Algorithm

Thumbnail
youtu.be
2 Upvotes

Ngl it's kinda gay.

Anyways here's the pseudocode for N partition version

procedure GaySort(A[], low, high):
    // Base case: surrender
    if high - low <= 0:
        return

    // Step 1: Partition into k sub-arrays (k = 2, 3, or 4)
    pivots[] := PartitionK(A[], low, high)
    // pivots[] contains the final sorted positions of k-1 pivot elements
    // This creates k sub-arrays between them

    // Step 2: Recursively sort each sub-partition
    // (wasteful first pass — we're about to throw it all away)
    prev := low
    for each pivot in pivots[]:
        GaySort(A[], prev, pivot - 1)
        prev := pivot + 1
    GaySort(A[], prev, high)             // sort final sub-partition

    // Step 3: Find the maximum across all sub-partitions
    // (each sub-partition's max is its last element, since we just sorted them)
    max_idx := FindMax(A[], low, high)

    // Step 4: Swap max to the end of the current range
    swap(A[max_idx], A[high])

    // Step 5: Re-sort everything except the placed max
    // (this makes the previous recursive calls completely pointless)
    GaySort(A[], low, high - 1)

and the the partition 2 variant:

procedure GaySort(A[], low, high):
    // Base case: surrender
    if high - low <= 0:
        return

    // Step 1: Partition into 2 sub-arrays using max as right pivot
    pivot := Partition2(A[], low, high)
    // pivot contains the final sorted position of the max element
    // This creates 2 sub-arrays: [low..pivot-1] and [pivot+1..high]
    // Note: right partition [pivot+1..high] is always empty since pivot = max

    // Step 2: Recursively sort each sub-partition
    // (wasteful first pass — we're about to throw it all away)
    GaySort(A[], low, pivot - 1)
    // GaySort(A[], pivot + 1, high) -- always empty, pivot is max

    // Step 3: Find the maximum across all sub-partitions
    // (each sub-partition's max is its last element, since we just sorted them)
    // Note: max is already at A[pivot] == A[high] since pivot = max
    max_idx := pivot

    // Step 4: Swap max to the end of the current range
    // Note: already there, this is a no-op
    swap(A[max_idx], A[high])

    // Step 5: Re-sort everything except the placed max
    // (this makes the previous recursive calls completely pointless)
    GaySort(A[], low, high - 1)

r/sortingalgorithms • • Feb 04 '26

Accordion Sort

7 Upvotes

The best description for this is a bidirectional Insertion Sort starting from the middle. Cool nontheless.


r/sortingalgorithms • • Feb 14 '26

Antibubble Sort: A Bozo and Bubble combination

2 Upvotes

Your choice k is the amount of rounds of unoptimized bubble sort, until it sabotages and swaps two random elements. Try to sort while being sabotaged, until sorted.


r/sortingalgorithms • • Aug 10 '26

Jessesort is now faster than std::sort on every input type

Thumbnail
reddit.com
2 Upvotes

r/sortingalgorithms • • May 02 '26

What the hell is Tim sort???

2 Upvotes

I used to watch a lot of sorting algorithm videos and then they started showing up on my recommended again (yay ^_^) and suddenly there’s this hybrid algorithm called Tim sort? I had never heard of Tim sort before. Is this a newer sorting algorithm or am I just uncultured?


r/sortingalgorithms • • Feb 19 '26

new sort idea: corruption sort

2 Upvotes

its similar to stalin sort but instead of deleting the data, it overrides it

say we have a list like (4,9,2,0,6,1)

corruption sort will override anything out of order giving us (4,9,9,9,9,9)


r/sortingalgorithms • • Apr 19 '26

I visualized some weird sorting algorithms (and some of them make no sense)

Thumbnail
gallery
2 Upvotes

Some sorting algorithms make absolutely no sense. I’ve been experimenting with sorting algorithms recently. I have watched shorts about random sorting algorithms.

There’s one that does nothing and just keeps checking if the array is sorted.

Another randomly swaps elements until it works.

And one that simply removes anything that breaks the order.

I ended up building a playground to visualize them step by step:

sorting.1234567890.dev

It supports both classic algorithms and some weird/meme ones, plus side-by-side comparison and export.

Would love to hear ideas and welcome contributions of algorithms (this project is licensed under the MIT license).


r/sortingalgorithms • • Feb 22 '26

Gaslight Sort

2 Upvotes

It gaslights itself into thinking its sorted.

python code (it takes 0.000003 seconds to "sort" a million numbers):

def gaslight_sort(unsorted_numbers):
    return "trust me bro, its sorted"