Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your algorithm is a sort-based shuffle, as discussed in the Wikipedia article.</p> <p>Generally speaking, the computational complexity of sort-based shuffles is the same as the underlying sort algorithm (e.g. O(<em>n</em> log <em>n</em>) average, O(<em>n</em>²) worst case for a quicksort-based shuffle), and while the distribution is not <em>perfectly</em> uniform, it should approach uniform close enough for most practical purposes.</p> <p>Oleg Kiselyov provides the following article / discussion:</p> <ul> <li><a href="http://okmij.org/ftp/Haskell/#perfect-shuffle" rel="nofollow noreferrer">Provably perfect random shuffling and its pure functional implementations</a></li> </ul> <p>which covers the limitations of sort-based shuffles in more detail, and also offers two adaptations of the Fischer–Yates strategy: a naive O(<em>n</em>²) one, and a binary-tree-based O(<em>n</em> log <em>n</em>) one.</p> <blockquote> <p>Sadly the functional programming world doesn't give you access to mutable state.</p> </blockquote> <p>This is not true: while purely functional programming avoids <em>side effects</em>, it supports access to mutable state with first-class effects, without requiring side effects.</p> <p>In this case, you can use Haskell's mutable arrays to implement the mutating Fischer–Yates algorithm as described in this tutorial:</p> <ul> <li><a href="http://brett-hall.blogspot.com/2008/01/haskell-shuffling.html" rel="nofollow noreferrer">Haskell Shuffling</a> (Brett Hall)</li> </ul> <h2>Addendum</h2> <p>The specific foundation of your shuffle sort is actually an infinite-key <a href="http://en.wikipedia.org/wiki/Radix_sort" rel="nofollow noreferrer">radix sort</a>: as gasche points out, each partition corresponds to a digit grouping.</p> <p>The main disadvantage of this is the same as any other infinite-key sorting shuffle: there is no termination guarantee. Although the likelihood of termination increases as the comparison proceeds, there is never an upper bound: the worst-case complexity is O(∞).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload