Chapter 5: Problem 2
Given an array \(A\) of length \(n\) (chosen from some set that has an underlying ordering), you can select the largest element of the array by first setting \(L=A[1]\) and then comparing \(L\) to the remaining elements of the array, one at a time, replacing \(L\) with \(A[i]\) if \(A[i]\) is larger than \(L\). Assume that the elements of \(A\) are randomly chosen. For \(i>1\), let \(X_{i}=1\) if an element \(i\) of \(A\) is larger than any element of \(A[1: i-1]\). Let \(X_{1}=1 .\) What does \(X_{1}+X_{2}+\cdots+X_{n}\) have to do with the number of times you assign a value to \(L ?\) What is the expected number of times you assign a value to \(L\) ?
Short Answer
Step by step solution
Key Concepts
These are the key concepts you need to understand to accurately answer the question.