# manually sorting cards

Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last
• 05-12-2008
cyberfish
manually sorting cards
Not exactly programming but...

I have a stack of 100 cards numbered 1-100. Distribution is random. With a memory restraint of the size of a desk, what is the most efficient way to sort it manually?

I did a bucket sort (into piles of 10) and then insertion sorts on the individual piles. Is there a more efficient way?

Thanks =)
• 05-12-2008
whiteflags
Try mergesort.
• 05-12-2008
cyberfish
Is mergesort more efficient? Since it's a comparison sort, it has a lower bound of O(nlogn) where bucket sort would do it in O(n) avg if I understand it correctly (according to wikipedia). And in this case, I do have the information required for bucket sort.
• 05-12-2008
whiteflags
No, I wasn't being helpful. I just wanted to see if you could do it. But mergesort is quite intiutive to real life, and you can definitely make minimal use of your desk. The only thing you need is a sorted pile and an unsorted pile. The idea is to build the sorted pile by inserting cards yourself. I think you can do it pretty fast. Maybe I'm too quick to judge on the helpfulness thing.
• 05-12-2008
laserlight
Quote:

But mergesort is quite intiutive to real life, and you can definitely make minimal use of your desk. The only thing you need is a sorted pile and an unsorted pile. The idea is to build the sorted pile by inserting cards yourself.
I think you are thinking of insertion sort rather than merge sort.
• 05-12-2008
cyberfish
Quote:

I think you are thinking of insertion sort rather than merge sort.
That is what I thought, too.
• 05-13-2008
MacGyver
Wow. We need lives.
• 05-13-2008
nvoigt
Quote:

Is there a more efficient way?
Hire 10 Indians or Ukrainians to do it for you ? ;)
• 05-13-2008
twomers
• 05-13-2008
brewbuck
Direct placement sort. Draw 100 squares on the ground, labeled 1-100. For each card, place it on the matching square. Now pick them up in order. (This is a special case of rank sort)

Even more efficient, don't sort the cards at all, but merely imagine that they are sorted.
• 05-13-2008
Neo1
Quote:

Originally Posted by brewbuck
Direct placement sort. Draw 100 squares on the ground, labeled 1-100. For each card, place it on the matching square. Now pick them up in order. (This is a special case of rank sort)

Even more efficient, don't sort the cards at all, but merely imagine that they are sorted.

Hmm

Code:

```int* DPSort(int *Data) {         int Table[100];         int SortedData[100];         unsigned int i = 0;         for(; i < 100; i++)         {                 Table[i] = i+1;         }                 for(i = 0; i < 100; i++)         {                 for(unsigned int j = 0; j < 100; j++)                 {                         if(Data[i] == Table[j])                         {                                 SortedData[j] = Data[i];                                 break;                         }                 }         }                 return SortedData; }```
Something tells me this will be very inefficient?

Edit: Ready to flame the first one to comment my poor code!
• 05-13-2008
Daved
That doesn't model brewbuck's idea. It relies on the fact that Table[j] always equals j+1. So remove your j loop and your if and simply set SortedData[Data[i]+1] = Data[i].

I would make either 10 or 20 piles and sort by the first digit in the number on the card first, then sort each individual pile as I picked them up.

The most efficient algorithm depends on how fast your mind can determine the proper location and deal the cards, not so much what the most efficient algorithm in code would be.
• 05-13-2008
PING
Quote:

Hire 10 Indians or Ukrainians to do it for you ?
Or maybe 100 Germans :)
• 05-13-2008
CornedBee
I would indeed go for bucket sort. Have ten stacks. Put 1-9 into the first, 10-19 into the second, and so on. (The first stack will have 9 cards, and the last 11. That's fine. It's worth the faster recognition.)

Then sort the individual stacks and put them together.
• 05-13-2008
Thantos
It kinda matters what type of cards these are also and how you want to sort them. For example if you were trying to sort two playing decks (104 cards) then I would just make a pile for each type of card (2s, 3s, Js, Qs, etc). If you wanted to do them by suit and rank then I'd probably just make 8 rows each with a suit and then put the card in the right spot (insertion sort) as I got to it.
Show 80 post(s) from this thread on one page
Page 1 of 3 123 Last