Блог пользователя Sajjat004

Автор Sajjat004, история, 9 месяцев назад, По-английски

Problem Statement
Suppose you have a fair dice with $$$m$$$ faces, numbered from $$$1$$$ to $$$m$$$. You roll this dice $$$n$$$ times independently, and each face has an equal probability of $$$ \frac{1}{m} $$$. Find the expected value of the maximum number obtained after these $$$n$$$ rolls.

Expected Maximum
If you roll an $$$m$$$-faced dice $$$n$$$ times, then there are $$$m^n$$$ possible combinations of rolls. The expected maximum is the average of the maximum values obtained from all $$$m^n$$$ combinations of rolls.

Intuition:
We have to compute the expected maximum value. That is:

$$$ \text{Expected max} = \sum_{i=1}^{m} i \cdot P(\max = i) $$$

Where $$$P(\max = i)$$$ = probability that the maximum number across $$$n$$$ rolls is exactly $$$i$$$.

Calculating $$$ P(\max = i) $$$

  • Each dice roll can result in one of $$$m$$$ outcomes: $$$1$$$ to $$$m$$$.
  • The probability that one roll gives a value ≤ $$$i$$$ is $$$\frac{i}{m}$$$.
  • For $$$n$$$ independent rolls, the probability that all of them are ≤ $$$i$$$ is: $$$ P(\text{all rolls} \le i) = \left( \frac{i}{m} \right)^n $$$

Now,

$$$ \begin{aligned} P(\max = i) &= P(\text{all rolls} \le i) - P(\text{all rolls} \le i - 1) \\ &= \left( \frac{i}{m} \right)^n - \left( \frac{i - 1}{m} \right)^n \end{aligned} $$$

So,

$$$ \text{Expected max} = \sum_{i=1}^{m} i \cdot \left( \left( \frac{i}{m} \right)^n - \left( \frac{i - 1}{m} \right)^n \right) $$$

This formula gives the expected maximum of rolling an $$$m$$$ faced dice $$$n$$$ times without enumerating all possible outcomes (which would be $$$m^n$$$).

  • Time Complexity: $$$O(m⋅logn)$$$
  • Space Complexity: $$$O(1)$$$

Problem Link: 453A - Little Pony and Expected Maximum
Solution Link: 332049084

  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Well Explained!!

»
7 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Challenge — Solve this for $$$m \leq 10^9$$$ and $$$n \leq 10^9$$$

  • »
    »
    7 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Is this possible? if you could calculate this in something faster than $$$O(n+m)$$$ wouldn't that imply a faster-than-$$$O(n+k)$$$ way to calculate $$$\sum_{i=1}^ni^k$$$?

    The EV here is (by tail sum formula) $$$E = \sum_{i=1}^m\left(1 - \left(\frac{i-1}{m}\right)^n\right) = m - \frac{1}{m^n}\sum_{i=1}^m (i-1)^n$$$, so if you can calculate $$$E$$$ quickly then $$$m^n(m - E) = \sum_{i=1}^{m-1}i^n$$$. I was under the impression that the RHS there cannot be calculated faster than the naive method for large $$$m$$$ and $$$n$$$ but perhaps that's wrong.

    • »
      »
      »
      7 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Sorry for my poor English, I meant to say one of the cases should hold. If both hold, then it is actually difficult.

      Next, to find $$$\sum\limits_{i=1}^{n} i^k$$$, we can use lagrange interpolation the complexity is $$$O(k \cdot log(n))$$$, which definitely works for large $$$n$$$. So, the original problem can be solve in $$$O(min(m \cdot log(n), n \cdot log(m)))$$$.