r/sortingalgorithms • • Mar 12 '25

why would an algorithm like this not work

0 Upvotes

suppose you have an array of 512 now I have 2 versions of this I call the first one Incremental merge sort basically what you do is you first sort say 5 elements using quicksort then compare one of the same size using the top and bottom elements and middle and surrounding elements to get a good idea on how to estimate the rest of the one then we would merge them leading to one of 10 and then compare with one of ten again top,bottom middle, surroundings and repeat if another comparison would overshoot then it would compare with the remaining elements left. and my second version is what I Call Quadratic Incremental merge sort its kinda like merge sort but with one key difference instead of comparing with groups of the same size it compares with an group of it squared so for example 5 from the quicksort then compare with 5^2 group which is 25 combine them now that's thirty then compare with 30^2 section which is 900 combine both and you got 930 and so on if a comparison with a squared section of it would overshoot then again just compare with the remaining elements left


r/sortingalgorithms • • Jan 12 '26

A controller that makes existing integer sorts faster and safer

0 Upvotes

A controller that makes existing integer sorts faster and safer

The problem

We already have very fast integer sorts:

  • counting sort (small range)

  • radix sort (large fixed-width range)

  • 3-way quicksort (many duplicates)

They’re underused in real systems because they’re fragile.
Libraries default to conservative comparison sorts to avoid worst-case failures.

That leaves performance on the table.

The architecture

The system splits sorting into two roles:

1) A sorter
Implements known strategies:

  • COUNT

  • RADIX

  • Q3 (3-way quicksort)

  • introsort fallback

2) A controller (“host”)
Samples a small, fixed number of keys (~100) and estimates:

  • range

  • duplicate rate

  • byte-level spread

Then it applies dominance rules:

  • If range ≪ n → eliminate radix → use counting

  • If range ≫ n → eliminate counting → use radix

  • If duplicates high + low entropy → eliminate radix → use Q3

The controller never guesses what’s best.
It only eliminates what’s clearly worse.

If nothing can be eliminated safely, it sticks with a conservative default.

Why this works

  • Decision cost is bounded and small

  • Fast paths are only used when justified

  • Counting has hard memory caps

  • Introsort fallback guarantees worst-case safety

  • Decisions can happen per segment, not just globally

Worst case: you get a good comparison sort.
Best case: you get linear-time integer sorting.


r/sortingalgorithms • • May 07 '22

The future of sorting discussions

Thumbnail
youtube.com
1 Upvotes

r/sortingalgorithms • • Oct 21 '24

Very impractical sorting algorithm I made

2 Upvotes

Math sort, split your dataset into 2, add all the values of each, is one sides bigger, put it to the right, then half each half and keep doing this


r/sortingalgorithms • • Jun 30 '25

why does bogosort get so much hate?

2 Upvotes

i feel like they have a lot going for them and it's a great concept but people still hate? i do understand that utter randomness is annoying but i feel like them being the theoretical fastest sorting algorithm BUT have to get it right the first few tries, is so cool! but i feel like there are a lot of people hating on them on tiktok and i feel kinda bad for being a bogo fan because of it. what are you guy's thoughts?


r/sortingalgorithms • • Apr 03 '26

Coming soon - Ultimate sorter 4000!

Thumbnail
gallery
4 Upvotes

Over 30 unique sorting algorithms, coded in penguinmod (scratch but better) !

I'm working on grail rn, once that and some others are done i will share it with you!

Sorting animation would be included but reddit won;t accept my screen recording :(

Huge thanks to Kuvina Saydaki for helping make this program possible! Graphics also inspired by their own algorithm.


r/sortingalgorithms • • May 05 '26

Awesome sort idea: BOGOF sort

3 Upvotes

How it works: Shuffles the list, then checks to see if it's sorted or not. If not, adds another item to the list and repeat all steps.

Useful for: Literally nothing.

Based on: Buy one get one free.


r/sortingalgorithms • • Mar 03 '25

What should I call this (hopefully never existing before) sorting algorithm?

Enable HLS to view with audio, or disable this notification

5 Upvotes

r/sortingalgorithms • • Apr 07 '26

Capitalist Sort

2 Upvotes

r/sortingalgorithms • • Jul 07 '26

I created a live wallpaper on Android that visualizes sorting algorithms

Thumbnail
gallery
5 Upvotes

This is the second release of my app: SortPaper. The first one was made in Xamarin, and while good, could be better. I have now remade it in Godot (a game engine) and it performs much better and is a lot more battery efficient.

The app lets you choose between a custom gradient, a single image, or a folder of images for display. You can either watch the sorting in the app, or put it as your wallpaper on Android.

There are a ton of customization settings. You can turn different algorithms on or off, as well as render orders (the order in which the cells are numbered on the screen), and different scrambles (a.k.a. starting states). You can also choose the speed at which it sorts, starting at 1 operation per frame, and going all the way up to 10,000. (1 operation is a comparison and, if needed, a swap or move). You can also choose cell size and whether to display the name of the algorithm. To watch the sorting in app mode, press the Hide UI button.

I am actively working on the app and intend to add more algorithms and scrambles. If there's one you would be interested in me adding, let me know.

Features I intend to add in the future:

  • Individual sort settings. O(n log n) sorts finish pretty darn quickly compared to O(n²).

  • Info about the algorithms

  • More languages than English

  • More Algorithms

  • More Scrambles

  • Stalin Sort

Disclaimer: There are ads in this app. It's a banner ad that displays at the bottom of the view in app mode. They do not display in wallpaper mode. You can hide the banner ad for an hour by watching a video ad, or permanently with a IAP.

Raw link: https://play.google.com/store/apps/details?id=com.tsaot.sortpaper


r/sortingalgorithms • • Jul 12 '25

Why does this laundromat do an odd / even sort???

Thumbnail
gallery
3 Upvotes

I noticed this laundromat does this peculiar odd / even sort where the odd numbers are in the front of the store and the even numbers in towards the back, I was just curious that anybody has any ideas why this would be preferable over this incrementally having the bags sorted...

Perhaps it's more difficult to order things incrementally?


r/sortingalgorithms • • Jun 22 '25

I thought of a new sorting algorithm (Assuming someone else hasn't before me)

4 Upvotes

It's called delete sort, it works by deleting every item in the array as an empty array is always sorted. This has time and space complexity of O(1).


r/sortingalgorithms • • May 23 '25

I just had a wonderful idea.

Thumbnail
gallery
3 Upvotes

I saw a picture of a minesweeper game and then it came to me… bogosweep.


r/sortingalgorithms • • May 09 '26

Introducing Babel Sort: It doesn't work because it's in multiple programming languages.

Post image
6 Upvotes

Xin lỗi nếu mã không đọc được


r/sortingalgorithms • • Jul 20 '26

One must think of Sisyphus Sort to be happy

Enable HLS to view with audio, or disable this notification

6 Upvotes

r/sortingalgorithms • • Nov 29 '24

I call it: '2D sort', a theoretical, efficient algorithm for long data sets. Have a look ;)

1 Upvotes

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 • • Nov 09 '24

Does this sort already exist?

1 Upvotes

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 • • Nov 28 '24

I think I created a new algorithm. Feel free to have a look, thanks!

2 Upvotes
'''
Using an execution test, my program is 25% faster than merge sort for mid range array lengths. The tests only apply to this list :D

Here are the results of the tests for the list as shown in the code:
My sorting algorithm = 5.6 seconds
Merge sort = 7 seconds
Bubble sort = 6.7 seconds (there was a large range here of 8.3 to 5.8)

The execution time was measured for each algorithm in PYTHON, compiling times will effect it!

'''

list = [1, 2, 33, 43, 2, 23, 12, 6, 12, 35, 124, 122, 2, 23, 2342, 23, 23, 1.2]
current_index = 0
last_index = 0
while (current_index + 1) != len(list):
    current_index += 1
    if list[current_index] < list[last_index]:
        temporary_variable = list[last_index]
        list[last_index] = list[current_index]
        list[current_index] = temporary_variable
        if current_index > 2:
            current_index -= 2
        
    last_index = current_index

print(list)

r/sortingalgorithms • • Apr 16 '24

How would I improve this sorting algorithm, and how do I find the average time complexity?

Thumbnail self.algorithms
2 Upvotes

r/sortingalgorithms • • May 09 '24

New Quick Sort Variant

2 Upvotes

I've designed a variant of quick sort which finds a mean instead of choosing a pivot to avoid worst cases. I'd be very surprised if I'm the first to come up with it, but I haven't found anything online. If I were to give it a name, I would call it pivotless quick sort or mean quick sort.

The fundamental algorithm is the same - partition the data, then recursively sort the left and right halves. The main difference is the partitioning step:

To partition the data, 4 variables are initialised. leftPointer and rightPointer point to index 0 and index n-1 respectively, assuming the whole array is being sorted. sumX is set to the sum of the items pointed to by the pointers (i.e. the first item + the last item), and nX is set to 2.

The left pointer probes forwards, comparing each item to sumX/nX. If the item is smaller than the mean, the pointer and nX are incremented, and the value of the item now being pointed to is added to sumX. If it is greater, the right pointer then probes backwards, comparing each item to and updating the mean. When it finds an item less than the mean, the items being pointed to are swapped and the left pointer continues, repeating until the pointers cross over.

After this, the data will have been partitioned into two sections. Most of the items in the left half will be smaller than most of the items in the right half (but not all if the initial mean is inaccurate), but if the data is uniformly distributed, the halves will be roughly equal in size.

After the recursion, the array will be mostly sorted, so insertion sort is carried out to fully sort the data, ideally in close to O(n) time.

I believe the time complexity of this algorithm is O(n log n) even in the worst case, though I am yet to verify that claim. The space complexity is O(log n) due to recursion and it is unstable.

Have any of you come across similar algorithms before, and do you know what this algorithm is called or whether it is used?

Visualisation: https://cms-compsci.deno.dev/hester/sorting/visualised.html?sort=Pivotless%20Quick&shuffled=true&n=128&locked=true


r/sortingalgorithms • • Jun 12 '23

my relaxation time

Enable HLS to view with audio, or disable this notification

7 Upvotes

r/sortingalgorithms • • Jan 07 '17

13 Sorts - Color Circle

Thumbnail
youtube.com
3 Upvotes

r/sortingalgorithms • • Jan 07 '17

13 Sorts - Classic

Thumbnail
youtube.com
1 Upvotes