5 comments on “Sorting in R as Inefficiently as Possible

  1. This post is hilariously funny: my belly was aching from laughing so hard!
    Thank you for posting this amazing blog entry!

  2. To be fair, shouldn't a bad sorting algorithm be required to have each step move toward creating a more sorted list? After all, one could just design an algorithm that attempts to factor a large product of primes (or some other computationally intensive task) between efficient steps (similar to the sleep algorithm).

    I nominate an algorithm that repeatedly iteratively takes minimum values from a vector. It's a bad sorting algorithm, but not intentionally bad or complex. Likewise, if the algorithm runs for a limited amount of time, it will partially sort a vector, whereas bogosort has no partial sorting.

    That being said, there's probably some trick involving Cartesian products which can be justified, and will easily gum up a system.

  3. a slightly more fair version is much faster:

    bogosort2 <- function(x)
    is.sorted = 0)
    while(x[1]!=min(x)) x <- sample(x)
    for(i in 2:n) {
    while(x[i]!=min(x[-(1:(i-1))])) x[-(1:(i-1))] <- sample(x[-(1:(i-1))])

Leave a Reply

Your email address will not be published. Required fields are marked *

Before commenting, please answer this simple arithmetic question to prove you aren\'t a spambot: *
Time limit is exhausted. Please reload CAPTCHA.