# What's the name of this sorting(?) algorithm?

Given the options of:

• Red
• Orange
• Yellow
• Green
• Blue
• Violet

You want to find your favorite color by comparing all pairs to each other, like so: Red vs...

• Red vs Orange = Orange
• Red vs Yellow = Red
• Red vs Green = Red
• Red vs Blue = Red
• Red vs Violet = Red

Orange vs...

• Orange vs Yellow = Orange
• Orange vs Green = Orange
• Orange vs Blue = Orange
• Orange vs Violet = Orange

Yellow vs...

• Yellow vs Green = Green
• Yellow vs Blue = Yellow
• Yellow vs Violet = Yellow

Green vs...

• Green vs Blue = Green
• Green vs Violet = Green

Blue vs...

• Blue vs Violet = Violet

In the end you'll find your "most preferred". Not sure if you get a full order of preference.

What's the name of this...thing?

Also as D.W. described, I believe it's solved by which color won most often. So in the example above:

• Orange = 5
• Red = 4
• Green = 3
• Yellow = 2
• Violet = 1
• Blue = 0
• (Where's the procedure, the well-defined steps that define an abstract solution, the algorithm?) – greybeard Dec 4 '20 at 8:28
• I don't know the "well-defined steps"; that's why I'm trying to find the name of this thing. – Byran Zaugg Dec 5 '20 at 0:50
• What you present is a relation, looks a partial order. Per title and tag, you refer to an algorithm using a definite article - I still miss any trace of it. A partial order may be "simple/total", but, e.g., not if represented as a graph, there is more than one node with an in-degree of zero; same for out-degree. It still may be embeddable in a total order. – greybeard Dec 5 '20 at 6:22

If we can assume that there is a total order on all colors: to find the largest element, there is a straightforward $$O(n)$$-time algorithm to find it: you scan through all colors, keep tracking of the largest element seen so far:
• Set $$m$$ to the first color.
• For each other color $$c$$:
• Set $$m := \max(m,c)$$.
(Here $$\max$$ refers to the larger of the two colors, i.e., whichever is more preferred.) There is no need to "sort" all of the colors to find the largest (most favorite) color.