82.6k views
4 votes
Given an unordered list of n numbers, what is the expectation of the number of times the max variable is assigned in the process of finding the maximum value?

a. n/2
b. n/e
c. n/3
d. n/4

1 Answer

3 votes

Final answer:

The expectation of the number of times the max variable is assigned in the process of finding the maximum value in an unordered list of n numbers is approximately n/e, because the probability that the current number is larger decreases with each new number considered.

Step-by-step explanation:

The question pertains to the expectation of the number of times the max variable is assigned in the process of finding the maximum value within an unordered list of n numbers. The process of finding the maximum value involves comparing each number in the list with the current maximum and updating the max variable if a larger number is found. If the list is unordered, every number has an equal chance of being the maximum until that point in the list.

On the first comparison, the max variable is assigned for sure. For every subsequent number, the probability that the current number is larger than the currently known max is 1/i, where i is the position of the current number in the list (since it could be any of the i numbers seen so far). Thus, the expected number of max assignments is the sum of the probabilities for every number in the list. This sum is the harmonic series which asymptotically approximates to n/e where e is the base of the natural logarithm and n is the total number of elements in the list.

Based on this information, the correct selection from the given options will be (b) n/e.

User Fivetentaylor
by
8.6k points