Beruflich Dokumente
Kultur Dokumente
For each element i, the cost of insertion is determined by the number of elements
> i which have already been inserted.
because no element can be greater than it. Rather than calculate the cost of
each permutation, we will use linearity of expectations to nd the expected cost
of inserting elements
know there are
(n i + 1)!
ni
1...n
(n i)!
1
=
(n i + 1)!
ni+1
1
1
ni+1 of the cases incur a cost of 1, ni+1 cases incur a cost of 2,
and so on up until n i. The expectation is therefore:
Similarly,
E[i] = (
2
ni
1
1
+
+. . .+
)=
(1+2+. . .+ni)
ni+1 ni+1
ni+1
ni+1
=
1
(n i)(n i + 1)
ni
=
ni+1
2
2
Which we need to sum over all elements i to get our nal expectation
E[Cost] =
n
X
ni
i=1
n1
1X
n (n 1)
1 (n 1)(n 1 + 1)
=
ni=
2 i=0
2
2
4
there are k places it can go in between and around the existing k-1 elements.
It is equally clear that the header pointer can be on any of the k-1 existing
elements.
k (k 1)
possible
There are
(k 1)
2 (k 1)
There are
2 (k 3) + 2 1
...
And so on, at each step i we have 2 more elements that can only nd 1 slot
that is i moves away
2 (k 2i + 1) + 2 (i 1) = (2k 2i)
To get the weighted sum, we now multiply each number of possibilities by
the weight of the moves and sum from 1 to the maximum number of moves
possible (k-1)
k1
X
i (2k 2i) =
i=1
k (k 1) (k + 1)
3
And the expectation of inserting the kth element is just that weighted sum
divided by the total number of possibilities
E[k] =
k(k1)(k+1)
3
k (k 1)
k+1
3
E[k] from 1 to n.
We'll
take the 1st and 2nd cases separately, since we know that the rst one will be
free (by denition) and the second one is necessarily 1.
E[Cost] = 0+1+
n
X
k+1
k=3
= 1+
k=3
k=3
1X
1X
1
k+
1 = 1+
3
3
3
n(n + 1)
1
1 2
3 + (n 2) =
n + 3n 4
2
3
6
3. The edge was not monochromatic after step 1, and monochromatic after
step 2
4. The edge was monochromatic after step 1, and not monochromatic after
step 2
We are most interested in cases 1 and 3 since they produce monochromatic
edges after step 2, which is what we are looking for. We observe that if we take
1
k probability that the
second will be colored the same as the rst. Thus, the probability that an edge
any two vertices and color the rst arbitrarily, there is a
P (Step1) =
1
k
1
P (Step1) = 1 =
k
k1
k
P (Step2|Step1) =
1
k
The case where an edge is not monochromatic after step 1 but is after step
2 is more complicated. We propose 3 cases
1. Neither vertex gets rerolled
2. One vertex gets rerolled
3. Both vertices get rerolled
We can ignore case 1 since this will clearly not produce a monochromatic edge.
A vertex will get rerolled if any one of its
r1
color. The chance that any neighbor is the same color can be calculated by the
following:
P (Reroll) = 1 P (N oM onoEdges) = 1
k1
k
r1
Thus the chance that Case 2 occurs multiplied by the chance that the reroll
makes it the same as the unrolled vertex is equal to
2 1
k1
k
r1 !
k1
k
r1 !
1
k
And the chance that Case 3 occurs multipled by the chance that the reroll
creates a monochromatic edge is
1
k1
k
r1 !2
1
k
r1 !
r1
r1 !2
1 k1
1
k1
k1
1
k1
1
+ 2 1
+ 1
=
k k
k
k
k
k
k
k
The expected value can be found by simply summing over all m edges
which all have
P (M ono) to
X
e E,
P (M ono) = m P (M ono)
eE
r1 !
r1
k1
k1
1
+
E[M onochromaticEdges] = m
+ 2 1
k2
k
k
m
=
k
1
k1
k
2r1 !
k1
k
r1 !2
k