Saturday, September 17, 2016

Algorithms: Usually Helpful Programs.

In my class recently we have been learning about algorithms and how they are used in computer programming.

Our textbook, "The Pattern on the Stone" by W. Daniel Hillis, describes algorithms as a "fail safe procedure, guaranteed to achieve a specific goal"(78). He described how his roommate devised an algorithm to sort his socks properly instead of just finding two socks and if they don't match he throws them back. In this new method he pulls them out one by one and puts them in a line, and if he finds two socks that are the same he takes them from the line and folds them together.

 I've recently been looking at algorithms, both good and bad, and found one that has really peaked my interest. It is called the Bogosort algorithm (shotgun sort, monkey sort and stupid sort are also names for this algorithm) and it is the most ridiculous algorithm I have ever seen. It is incredibly ineffective as a computer program or even in real life as it randomly sorts data until they are in the correct order. Say you have a deck of cards and you wish to sort them in order. Using bogosort, you'd basically throw them in the air and pick up the cards at random, then you'd check the new shuffled deck and if it was not in order you'd toss them again and again until they were perfectly sorted. If it were written as a computer program it would look somewhat like this:

while not inOrder(deck)
      shuffle(deck)

The algorithm itself has an average case of (n-1)n! (where n is the number of tries), so the number of attempts to sort it far out numbers the number of comparisons it makes. It only checks a couple of comparisons, no matter how large the list, before just shuffling the whole list again. However because this is an algorithm, there is a very small chance that this shuffling could sort these in the correct order, although that would take a horribly long time.

It is hilariously ridiculous, and honestly the worst algorithm I've ever seen.
Bogosort can be traced back to 1984 and is written in "The New Hacker's Dictionary" [7] as ".... It serves as a sort of canonical example of awfulness. Looking at a program and seeing a dumb algorithm, one might say 'Oh, I see, this program uses bogo-sort'". So even in the Hacker Dictionary it is known as one of the worst algorithm/programs out there.

A similar algorithm is the Bozo sort. It deals with a list of random numbers and if these numbers are not in order, the program will swap two of these numbers at random and then check again to see if its sorted and it continues on such as the Bogosort. With these kinds of programs the best you can hope for is that the lists are already sorted ahead of time or else this program could take forever to figure itself out.

I do not know if anyone has tried this method of sorting with a deck of cards, and  I imagine it would be incredibly time consuming and tedious. If just one card was out of place they would have to toss the whole deck again and pick it back up in a random order. I personally do not want to waste days of my life trying to sort anything by this algorithm.

I got most of my resources from this Wikipedia article https://en.wikipedia.org/wiki/Bogosort and http://www.hermann-gruber.com/pdf/fun07-final.pdf for some more information on Bogosort.

No comments:

Post a Comment