Over time, all molecules slower than the threshold will be on side A, and all faster will be on side B. This has sorted the numbers into those less than a certain value and those larger than the same value.
If either side of the container contains more than one molecule, partition it with another barrier and demon, and apply the algorithm recursively.
When all sections of the container have only one molecule, read off their speeds in order to give the sorted list of numbers.
This procedure must then be carried out for each half of the molecules, recursively, so we need to add (n/2)! collisions (just one times this, since the two subsets can be performed in parallel).
We can see that the total complexity of the algorithm is O(n! + (n/2)! + (n/4)! + (n/8)! + ... + 1!). There are log2 n terms in this sum, but each is smaller by a factor of 2. I think this makes the overal complexity O(n! log(log n)), but I could be wrong...*
However, this algorithm not only sorts the list of numbers into numerical order, it produces a temperature gradient across the sections of the container, from cold to hot, from an initial uniform temperature, without doing any work. This temperature gradient can be used to drive a heat engine, producing useful energy.
So besides being a practical sorting algorithm, demon sort is also a free energy generator. By using the energy generated to operate the computational device on which the demon sort algorithm runs, one produces a workable perpetual motion device!
*In fact, Mike Rosulek writes:
Demon sort is actually O(n!) instead of O(n! log log n). This can be seen by applying the master theorem for recurrences on T(n)=n!+T(n/2). See case 3 in Wikipedia's version. Even if the demon doesn't do both recursive cases in parallel (i.e., we have n!+2*T(n/2)), the factorial still overwhelms the running time.