More Than Five
More Than Five

Reputation: 10419

Name of this sorting algorithm?

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?

Upvotes: 1

Views: 90

Answers (2)

SomeWittyUsername
SomeWittyUsername

Reputation: 18348

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

Upvotes: 7

AxxG
AxxG

Reputation: 204

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

Upvotes: 0

Related Questions