idm

May 7, 2010

3 Responses to “veridis quo”

  1. Christian Perfect Says:

    I can’t really follow your maths — where did the thing about coin-toss sequences being the same as $\binom{2k+1}{k+1}$? I assume $k$ is the number of coin tosses.

    The number of ways of tossing $n$ coins and getting $k$ heads is $\binom{n}{k}$. That’s where the Pascal triangle stuff comes in – the number at the $k$’th column in the $n$’th row of Pascal’s triangle is precisely $\binom{n}{k}$.

    You don’t even need to get that complicated though. Increment sort of [1,0] will take $n$ steps only if it looks at the wrong element $n-1$ times, and then finally looks at the correct element once. This set-up is within grasping distance of high-school maths: it’s the geometric distribution. Using that fact, the expected number of iterations is $\frac{1}{0.5} = 2$.

  2. nanotone Says:

    Oops, I wasn’t clear enough about the relationship to traversals of Pascal’s triangle. I used 2k+1 just to force the number of coin-tosses to be odd. A successful sort of [1,0] always has k heads and k+1 tails, for some positive integer k. That’s where $\binom{2k+1}{k+1}$ comes from.

    And again, this binomial coefficient needs to be adjusted to include only valid coin-toss sequences, i.e. those that wouldn’t have terminated any earlier.

    Judging from your last paragraph though, it looks like you might not have grasped the profound ineffectiveness of increment sort yet. Remember: wrong elements are also incremented when chosen, which moves the list farther away from sorted-ness. That’s why Pascal’s machinery is invoked.

  3. snow Says:

    He finally found the answer!

Leave a Reply