How fast can you find the maximum? (A surprising result!)
by greenturtle3141, Nov 13, 2021, 5:52 AM
Reading Difficulty: 3-4/5
Prerequisites: Definitely need to know what a graph (...with vertices and edges) is. Good to be familiar with linearity of expectation.
Professor Tkocz was the substitute professor for combinatorics class today... and it was wild! Here's what I learned.
Part 1: Introduction
I hand you a list of
numbers. How fast can you find the largest one?
One way to find the largest is pretty simple: Go through the numbers one-by-one, and keep track of the biggest one you've seen before. You're done once you reach the end of the list. Because of the linear nature of this algorithm this, is an
algorithm. That is, this algorithm needs you to compute at most
comparisons for some
and
.
It's evident that we can't do better than
comparisons (Exercise: Why?), so this is boringly optimal. Post is done yay.
What if I gave you a team of
people (including you) to find the maximum of a
-element list? How fast can you do it then?
You guys all get to work in parallel. Everyone can think at the same time and share information infinitely fast... Can you come up with a really fast strategy to find the maximum?
In general, suppose I give an
-element list of numbers to a team of
people. How fast can they find the maximum element? Mathematicians have suspected that with a clever enough general algorithm, this can be done in constant time, i.e.
. We just couldn't find one. Is it possible?
Eventually, we got our answer.
THEOREM: No matter what algorithm you use,
parallel processors cannot find the maximum of an
-element list in constant time. In particular, any maximum-finding algorithm has worst-case time complexity at least
.
Why Big-Omega and not Big-O?
To be more precise: An algorithm will consist of several rounds, where in each round we make
comparisons at once (which pairs of numbers we decide to compare in a round may be decided based on the results of the previous round). For example, if
and my list is
, an algorithm could do this:
Modelling an "algorithm" in this way, the Theorem states that the number of rounds is at least
in the worse case, no matter how clever you are.
Let's prove this!
Part 2: Turán's Theorem
We need to talk about some graph theory here. The graphs we'll consider are simple ones: They're finite, no loops, have undirected edges, no multi-edges... they're all nice.
Definition: Let
be a graph. A subset
of the vertices is an independent set if no two vertices in
are connected by an edge.
Pretty intuitive definition. Moving on:
Definition: The independence number of a graph
, denoted by
, is the maximum size of an independent set.
For example (verify these!):
The question is: How big must
be? That is, if there are
vertices and
edges, can we guarantee that there must exist an independent set whose size is at least <some formula in terms of
and
>? Turán's Theorem answers this.
Theorem (Turán):
Proof. The idea is to use the probabilistic method
of
with the integers
. Using
, we may generate an independent set
as follows:
Here,
is the set of neighbors of
. To describe
in other words, each
is such that over
and all its neighbors,
has the least label.
Note that indeed
forms an independent set (Proof)
is chosen uniformly at random over all labelings? To compute this, we write
as a sum of indicator random variables
Taking the expectation and applying linearity of expectation, we get:
By a simple counting argument
. So we have:
We're almost there. How can we wrestle this into the desired lower bound? The punchline is to apply the AM-HM inequality on the sum! Recall by the Handshake Lemma that:
So using
:
This rearranges to
. By the probabilistic method, we deduce that there exists an independent set of size at least
, hence it certainly follows that
. 
Apparently this bound is actually pretty tight, and there are some nice corollaries you can deduce from this. But I won't discuss this, for we have bigger fish to fry!
Part 3: The Main Event
Theorem: Any algorithm for finding the maximum of an
-element list, using
parallel processors, must have worst-case time complexity at least
(provided that a comparison is an
operation).
Proof. Considering the "rounds" structure described in the introduction, note that each round can only really tell you so much about which numbers is the maximum. In fact, a round of comparisons may even leave you with a subset of vertices that you have no information on, in the sense that you don't know the order of any two vertices in the subset. Hmm... doesn't that smell like "independent sets"? Controlling the size of such a subset is the key machinery in this proof.
This idea is captured by the following Lemma:
Lemma: Let
be the worst-case minimum number of rounds needed to determine the largest element of an
-element list using
parallel processors. Then:

Proof. Let the list be
. Suppose an algorithm decides to compare
in the first round. Now construct a graph
whose vertices are
and with
edges
. By Turán,
. Hence there exists an independent set
with size at least
. Now we argue:
Since we spent a first round, we must add
, giving the desired lower bound
. 
Going back to the main proof, the rest is just some algebra and hand-waving. By handwaving, I mean that I will now drop the ceiling function and leave it to the reader to make this more rigorous, otherwise this would be unpleasant to read.
The number we are bounding is
. Let's just keep plugging this into the Lemma.

In general (by induction), we have that
for all
... kinda. Once the number of vertices left,
is
or less, we can't go further. Hence,
where
is the least integer for which
. Manipulating this:



Q.E.D. 
Prerequisites: Definitely need to know what a graph (...with vertices and edges) is. Good to be familiar with linearity of expectation.
Professor Tkocz was the substitute professor for combinatorics class today... and it was wild! Here's what I learned.
Part 1: Introduction
I hand you a list of

One way to find the largest is pretty simple: Go through the numbers one-by-one, and keep track of the biggest one you've seen before. You're done once you reach the end of the list. Because of the linear nature of this algorithm this, is an




# I HAVE NO IDEA WHY THIS CODE IS SUCH A BAD COLOR AND IM SORRY FOR MY SINS
def findMax(nums):
currMax = nums[0]
for num in nums:
if num > currMax: # This gets called at most n+1 times, so findMax is O(n)
currMax = num
return currMax
It's evident that we can't do better than

What if I gave you a team of


You guys all get to work in parallel. Everyone can think at the same time and share information infinitely fast... Can you come up with a really fast strategy to find the maximum?
In general, suppose I give an



Eventually, we got our answer.
THEOREM: No matter what algorithm you use,



Why Big-Omega and not Big-O?
- Big-
is for upper bounds. For example, both
and
are
.
- Big-
is for lower bounds. For example, both
and
are
.
To be more precise: An algorithm will consist of several rounds, where in each round we make


![$[x_1,x_2,x_3,x_4]$](http://latex.artofproblemsolving.com/b/7/1/b718b28f5a968d3ccd5388da20676cb0939afb36.png)
- Round 1: Compare the pairs
.
- Result:
,
,
, and
. (Note that this is not enough to find the max! Could be
or
.)
- Round 2: Compare the pairs
.
- Result:
, etc.
- Conclusion:
is the maximum.
Modelling an "algorithm" in this way, the Theorem states that the number of rounds is at least

Let's prove this!
Part 2: Turán's Theorem
We need to talk about some graph theory here. The graphs we'll consider are simple ones: They're finite, no loops, have undirected edges, no multi-edges... they're all nice.
Definition: Let



Pretty intuitive definition. Moving on:
Definition: The independence number of a graph


For example (verify these!):
, where
is the complete graph on
vertices.
, where
is the graph whose vertices and edges correspond to those of a cube.
where
is the complete bipartite graph on two vertex sets of size
and
.
The question is: How big must





Theorem (Turán):

Proof. The idea is to use the probabilistic method
If the expected value of something is
, then it must be possible to be at least
. Here, we construct a random process that generates an independent set. If the expected size of this set is
, then there must be an independent set of size at least
. Nothing too deep!
. To wit, consider a random labelling 



![$\pi:V \to [n]$](http://latex.artofproblemsolving.com/b/1/c/b1cdc4d8413965f951ac49a0dfa0e36a6ff67b98.png)











Note that indeed

If not, then you can find
such that
is an edge.
. Now, what is its expected size when 

- Since
and
, we have
.
- Since
and
, we have
.


If
is some set, then
when
, and otherwise
if
.
:






First decide which labels are assigned to
and its
neighbors. Then the probability that
gets the lowest of these labels is always
.
, 












Apparently this bound is actually pretty tight, and there are some nice corollaries you can deduce from this. But I won't discuss this, for we have bigger fish to fry!
Part 3: The Main Event
Theorem: Any algorithm for finding the maximum of an




Proof. Considering the "rounds" structure described in the introduction, note that each round can only really tell you so much about which numbers is the maximum. In fact, a round of comparisons may even leave you with a subset of vertices that you have no information on, in the sense that you don't know the order of any two vertices in the subset. Hmm... doesn't that smell like "independent sets"? Controlling the size of such a subset is the key machinery in this proof.
This idea is captured by the following Lemma:
Lemma: Let




Proof. Let the list be









- Since
is independent, this means that we have no information on how any two elements in
compare.
- In the worst case scenario, the maximum will lie in
.
- Hence, in the worst case, finding the maximum of
is at least as hard as finding the maximum of
.
- In other words, the number of more rounds we need to find the maximum of
, in the worse case, is at least the number of rounds we'd need to find the maximum of just those elements in
.
- As
, this number is given by
.
Since we spent a first round, we must add



Going back to the main proof, the rest is just some algebra and hand-waving. By handwaving, I mean that I will now drop the ceiling function and leave it to the reader to make this more rigorous, otherwise this would be unpleasant to read.
The number we are bounding is


In general (by induction), we have that












This post has been edited 3 times. Last edited by greenturtle3141, Nov 13, 2021, 6:00 AM