Given the algorithm to compute the maximum of an array of numbers. Assuming that the numbers appear in the array in random order.
What is the probability that the condition 'if ($a[i]>$max)'
1) is true exactly one time?
2) is true $n$ times?
I figured the answer to 1) is $\frac{(n-1)!}{n!}$ and 2) $\frac{1}{n!}$
Those are just my thoughts. I can't seem to justify them.
For $a_i > \max_{j < i} (a_j)$ to be true exactly once, that means that there is only one time where a value in the array is larger than all of the values that come before it. Note that (I assume) $a_1 > \max$ is considered to always evaluate to true, so your check has to fail for all $i > 2$, which means that $a_2 < a_1$, and also $a_3 < a_1$, and so forth, i.e. $a_1$ is the maximum of the array. What's the probability of that happening for a random array? Well, there are $n!$ ways to arrange the elements of the array, but $1 \times (n-1)!$ ways to put the maximum as $a_1$ and then randomly permute the rest. So the probability of that happening is $\frac{(n-1)!}{n!} = \frac{1}{n}$.
For the condition to be true $n$ times, it has to be true for every element - $a_1 > \emptyset$, $a_2 > a_1$, $a_3 > \max(a_1, a_2) = a_2$, and so forth. In other words, the array has to be sorted in ascending order. How many ways can you do that? Just the one. So the probability of it happening is $\frac{1}{n!}$.