Corrupted Bubble Sort continues…

I wanted a much better image of the curve I produced before I posted a question, so I re-made my algorithm in Python. It has a simple Pygame visualizer.

sortapproachpython1
720×720 Corrupted Bubble Sort, in an early stage of sorting.

Python is plenty fast for these tests, and it allows me to quickly complete simulations with decent settings.

sortapproachpython3
8192 samples, 8192 possible values -> 768×768 screen resolution, completed simulation with derivative.

I represent the derivative of the curve in yellow. Usually this is a rather messy line, because of the large amount of randomness that still exists in the sorted samples. (I also waned the odds of randomization too quickly in the above image, resulting in a misshapen curve with a steeper drop on one side.)

To get a smoother curve, I run many simulations in parallel, then draw the average.

sortapproachparlin4-4096-800-complete-s
The average of 4096 simulations of 800 samples – this is the image I used for my question on Quora.

I posted this question on Quora. Lev Kyuglyak responded that it may be a logistic function that produces a sigmoid curve, and that it could be can be represented in the form:

f(x)={\frac  {L}{1+{\mathrm  e}^{{-k(x-x_{0})}}}}

I am skeptical that my program can create a real sigmoid curve, because those graphs have an infinite domain, while the results of my simulations always have a domain of exactly [0,1]. perhaps my program compresses that infinite distance into a very small space as it approaches the left or right of the array. I’m currently thinking of ways to modify my program to have a much larger domain around the point of inflection.

The first change I’ve tried is to modify the probability of randomization with the difference between a traveling sample and its surroundings. samples that are closer in value to their surroundings have a lower chance of randomization and thus travel farther, perhaps forming larger flat areas at the start and end of the curve.

They kinda do, but not in the way I expected.

sortapproachrelative5-1024x-finished

Weirdness!

Leave a comment