1

You have a shuffled set of cards. You have to re-order them.

You do this by assigning each card a number based on its value (jack = 11, queen - 12) etc and its suite (hearts = 0, clubs = 1 ...). Each card gets unique number by formula (14 * suite) + value. You then have an empty array of 52 elements and just put each card in its correct position. This is very fast - big o would be O(N). What is the name for this approach?

2 Answers 2

7

It's called Counting Sort. You gain speed on expense of space.

Sign up to request clarification or add additional context in comments.

7 Comments

Is it bucket sort ? Is it counting sort or something like this, OP simply puts elements to right position without comparing elements with each other.
@Anton You're totally right, thanks! My only excuse is that it's same family and counting sort is actually a trivial version of bucket sort...
Somewhat amusing how many upvotes this got while being wrong. :-)
@RandyHoward well, it wasn't completely wrong, see my previous comment :)
Yeah, it's probably splitting hairs at this point, unless it's for a homework assignment where he needs to be specific.
|
0

I think, there is no special name for it. It is a kind of insertion sort with unique identification of objects.

Here is an overview

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.