Exercise · Volume 1 · 1.2.10-7
Exercise 1.2.10-7
not stated yet in Lean solution written
| Rating | M27 |
|---|---|
| Markers | M (mathematical) |
| Kind | K7, analyze: find the mean, the variance or the distribution of a cost from the written solution |
| Section | Section 1.2.10 of Volume 1. Companion chapter: Analysis of an algorithm |
The task
Find the distribution of when the keys contain exactly distinct values and are otherwise random.
The exact wording is in your copy of the book.
Hints
Open one hint at a time. Try the exercise again after each.
Hint 1
Only the rightmost occurrence of each value can make M4 run.
Hint 2
Fix the pattern of equal values, and see what remains random.
Solution
Show the solution
Assume that the values are , that each occurs at least once, and that all such sequences are equally likely. (Only the relative order of the values matters for Algorithm M.)
Step M4 runs for position exactly when for all . If the value occurs again at a position to the right of , this fails. So only the rightmost occurrence of each value counts. Let the rightmost occurrences be at the positions , and let , a permutation of . The values at the other positions are not larger than values to their right in a way that matters: a non-rightmost occurrence of a value has to its right, so it never counts. Hence equals the number of times M4 runs when Algorithm M works on alone.
Now sort the sequences by the partition of the positions into the classes of equal value. Each partition into classes comes from exactly sequences, one for each assignment of the values to the classes, and the permutation runs through all permutations once. So within each partition is uniformly random, and has the distribution of Section 1.2.10 for keys:
for every , and it does not depend on the partition or on .
Check
Take , . All sequences with each of are enumerated by Python. The distribution of is for , which is .
Remarks
The result changes when more is known, for example the numbers of copies of each value (Exercise 1.2.10-18). The mean of is .
This solution is drafted, and a person has not reviewed it yet. The source.
In Lean
not stated yet The exercise is not stated in Lean yet.
The status is computed from the Lean build. The node of the map.
Something is wrong? Report it.