Let be some constant (independent of the input array length ). Recall the Partition subroutine employed by the QuickSort algorithm, as explained in lecture. What is the probability that, with a randomly chosen pivot element, the Partition subroutine produces a split in which the size of the smaller of the two subarrays is times the size of the original array?

ANSWER: If the picked pivot is one of the smallest elements in the array, then the left partition’s size will be less than . Similarly, if the picked pivot is one of the largest elements in the array, the right partition’s size will be less than . Hence, there are elements that we can pick such that both partitions have size greater than or equal to . Since the algorithm picks a pivot randomly, all elements have an equal probability of getting picked as the pivot, i.e. . Therefore, . Option 1 is correct.

Now assume that you achieve the approximately balanced splits above in every recursive call — that is, assume that whenever a recursive call is given an array of length , then each of its two recursive calls is passed a subarray with length between and (where is a fixed constant strictly between and ). How many recursive calls can occur before you hit the base case? Equivalently, which levels of the recursion tree can contain leaves? Express your answer as a range of possible numbers , from the minimum to the maximum number of recursive calls that might be needed.

ANSWER: If , then , thus the branch with subarray length will have greater recursion depth.

If is the height of the recursion tree,
Taking on both sides
By log rule

The best case is . Since both and are less than , so, their logarithms are negative. Adding one more negative symbol on that results in an overall positive value for minimum and maximum depth. Therefore, option 1 is correct.

Define the recursion depth of QuickSort to be the maximum number of successive recursive calls before it hits the base case — equivalently, the number of the last level of the corresponding recursion tree. Note that the recursion depth is a random variable, which depends on which pivots get chosen. What is the minimum-possible and maximum-possible recursion depth of QuickSort, respectively?

ANSWER: Option 1 is correct.

Consider a group of k people. Assume that each person’s birthday is drawn uniformly at random from the possibilities. (And ignore leap years.) What is the smallest value of k such that the expected number of pairs of distinct people with the same birthday is at least one?

[Hint: define an indicator random variable for each ordered pair of people. Use linearity of expectation.]

ANSWER: For each pair of people in the room, let be an indicator random variable such that: ( may have been born on any of the days, and on any of the remaining days).

If 𝐸[𝑋] =1,𝑘 (𝑘 1) =365 2
Rewriting as a general quadratic equation 𝑎𝑥2 +𝑏𝑥 +𝑐 =0, for which 𝑥 is given by 𝑏±𝑏24𝑎𝑐2𝑎
𝑘2 𝑘 730 =0,𝑎 =1,𝑏 =1,𝑐 =730 𝑘=1±1+29202=1±54.052=1±27.02

Since the number of people cannot be negative, 𝑘 28. Option 2 is correct.

Let 𝑋1,𝑋2,𝑋3 denote the outcomes of three rolls of a six-sided die. (i.e., each 𝑋𝑖 is uniformly distributed among 1,2,3,4,5,6, and by assumption they are independent.) Let 𝑌 denote the product of 𝑋1 and 𝑋2 and 𝑍 the product of 𝑋1 and 𝑋3. Which of the following statements is correct?

  • Y and Z are independent, but 𝐸[𝑌𝑍] 𝐸[𝑌] 𝐸[𝑍]
  • Y and Z are not independent, but 𝐸[𝑌𝑍] =𝐸[𝑌] 𝐸[𝑍]
  • Y and Z are not independent, but 𝐸[𝑌𝑍] 𝐸[𝑌] 𝐸[𝑍]
  • Y and Z are independent, but 𝐸[𝑌𝑍] 𝐸[𝑌] 𝐸[𝑍]

ANSWER: For 𝑌 and 𝑍 to be independent, by definition, the two events [𝑌 =𝑥1] and [𝑍 =𝑥2] must be independent  x1, x2. If we choose 𝑥1 =𝑥2 =1, then 𝑃𝑟[𝑌 =1 AND 𝑍 =1] is the probability that the outcome of all three rolls was one. Since each roll is independent, this is equal to 163. 𝑃𝑟[𝑌 =1]𝑃𝑟[𝑍 =1] =136 136 =164

Clearly, 𝑃𝑟[𝑌 =1 AND 𝑍 =1] 𝑃𝑟[𝑌 =1] 𝑃𝑟[𝑍 =1], therefore, 𝑌 and 𝑍 are not independent.

Covariance reference: Expectations on the product of two dependent random variables

𝐶𝑜𝑣[𝑋,𝑌]=𝐸[(𝑋𝐸[𝑋])(𝑌𝐸[𝑌])]=𝐸[𝑋𝑌]𝐸[𝑋𝐸[𝑌]]𝐸[𝑌𝐸[𝑋]]+𝐸[𝐸[𝑋]𝐸[𝑌]]=𝐸[𝑋𝑌]𝐸[𝑋]𝐸[𝑌]𝐸[𝑋𝑌]=𝐶𝑜𝑣[𝑋,𝑌]+𝐸[𝑋]𝐸[𝑌]𝐸[𝑌𝑍]=𝐶𝑜𝑣[𝑌,𝑍]+𝐸[𝑌]𝐸[𝑍] (*)𝐸[𝑌]=136(1(1+2+...+6)+2(1+2+...+6)+...+6(1+2+...+6))=136(1+2+...+6)2=136212=12.25

Clearly, 𝐸[𝑍] is the same.

𝐶𝑜𝑣(𝑌,𝑍) =6𝑖=1(𝑦𝑖 𝐸(𝑌))(𝑧𝑖 𝐸(𝑍))
𝑦𝑖 {1 1,1 2,...,6 1,...,6 6} and clearly 𝐸(𝑌). Similarly, 𝑧𝑖 𝐸(𝑍). Therefore, 𝐶𝑜𝑣(𝑌,𝑍) 0, and from expression ( ),𝐸[𝑌𝑍] 𝐸[𝑌]𝐸[𝑍]. Option 3 is correct.

Leave a comment