0
$\begingroup$

Let $f(n)$ be the smallest number for which the following statement is true: "Any deck of n cards in any order, we can sort using at most $f(n)$ comparisons." What can you say about $f(52)? f(n)?$

attempt: Suppose $f(n)$ be the smallest number for which the following statement is true: "Any deck of n cards in any order, we can sort using at most $f(n)$ comparisons." Then if we start with 52 cards, and shuffle them, then there are $n!$ possible ways to order the deck of cards. So $f(n) = n! $, and so we have at most $f(52) = 52!$ comparisons.

I don't really know if this makes sense. Could someone please give me some feedback or help me? Thank you!

  • 0
    Look through the deck, one card at a time, keeping track of the lowest card. This lets you find the lowest card with $n-1$ comparisons. You can then find the second lowest with $n-2$, and so on. In total this method will take $(n-1)+(n-2)+\cdots+1=(n-1)(n-2)/2$ comparisons, much less than $n!$.2017-02-07
  • 0
    Question: If you fix an ordering for the cards, Why do you need comparisons? Consider the simpler case where you have 5 objects a,b,c,d,e, presented in any order. Let's make one up for illustration. d,b,a,e,c. You know how the cards must be ordered, and you know where they must end up. So we will just switch them into place pairwise. Since d must go in slot 4, we switch it with e, acquiring e,b,a,d,c. Proceeding, we have c,b,a,d,e -> a,b,c,d,e. The only reason this works is because we know the ordering, and we know every value appears once and only once. But never do we compare two cards.2017-02-07
  • 0
    So what you are saying is , if we start with 13 cards say, and then we will have to do 12 comparisons , so card number 1 won't be compared with anything, but card 2 will be compared with card 1, card 3 will be compared with card 1 and 2, and so on, so finally card 13 will be compared with 12 cards, so there are 1 + 2 + 3 + ....+12 = 78 possible comparisons?2017-02-07
  • 0
    So for the case with n cards, there would be 1 + 2 + ....+ (n-1) +(n) possible comparisons?2017-02-07
  • 0
    I need comparisons because that is how the problem is stated2017-02-07

1 Answers 1

3

See OEIS sequence A036604 and references there.

$f(n) \ge \log_2(n!)$ because $k$ comparisons can only have $2^k$ possible results, while there are $n!$ permutations that have to be distinguished. There are upper bounds coming from various sorting algorithms. The exact value of $f(52)$ seems to be unknown.

  • 0
    So where does this $log_2(n!)$ come from ?2017-02-07
  • 1
    @Mahidevran: There are $n!$ possible orders. You need to find the one that is correct. Each comparison can at most decrease the number of possible orders by a factor of $2$, so you need that many comparisons to reduce the number of possible orders to $1$. It is possible that you cannot achieve this efficiency, which is why it is a lower bound.2017-02-07