(a) The event that the 'ith' smallest number in the array is chosen as the pivot can only happen if the pivot is chosen from a subset of size 'i' from the array. The probability of choosing the pivot from this subset is 1/'i', since all elements in the subset are equally likely to be chosen as the pivot. Therefore, we have:

E(Xi) = 1/'i'

(b) The running time of randomized quicksort on an array of size 'n' can be divided into three parts: the time it takes to partition the array (which depends on the choice of the pivot), the time it takes to recursively sort the two subarrays on either side of the pivot, and the time it takes to combine the sorted subarrays.

Let's denote the running time of randomized quicksort on an array of size 'i-1' as T('i-1'), the running time on an array of size 'n-i' as T('n-i'), and the time it takes to partition and combine the arrays as (n). The running time of quicksort on an array of size 'n' can be expressed as:

T(n) = T('i-1') + T('n-i') + (n)

Taking the expected value of both sides:

E[T(n)] = E[T('i-1') + T('n-i') + (n)]

Using linearity of expectation:

E[T(n)] = E[T('i-1')] + E[T('n-i')] + E[(n)]

Since the choice of the pivot is independent of the running time, we can replace the expectations of T('i-1') and T('n-i') with the expectation of Xi:

E[T(n)] = E[Xi] * (T('i-1') + T('n-i') + (n))

Using the result from part (a), we have:

E[T(n)] = (1/'i') * (T('i-1') + T('n-i') + (n))

(c) To prove that ET(n)] = 2. nET() + (n), we need to find the expected value of Xi and substitute it in the equation derived in part (b).

From part (a), we know that E(Xi) = 1/'i'. Therefore, we have:

E[T(n)] = (1/'i') * (T('i-1') + T('n-i') + (n))

To find the expected value of T(n), we need to consider all possible values of 'i' from 1 to 'n'.

Summing over all possible values of 'i':

E[T(n)] = Σ (1/'i') * (T('i-1') + T('n-i') + (n)) (from 'i' = 1 to 'n')

Expanding the summation:

E[T(n)] = (1/1) * (T(0) + T('n-1') + (n)) + (1/2) * (T(1) + T('n-2') + (n)) + ... + (1/'n') * (T('n-1') + T(0) + (n))

Grouping the terms:

E[T(n)] = (1/'n') * [(n) + T(0) + T('n-1')] + (1/('n-1')) * [(n) + T(1) + T('n-2')] + ... + (1/1) * [(n) + T('n-1') + T(0)]

Simplifying the expression:

E[T(n)] = (n) * [1/'n' + 1/('n-1') + ... + 1/1] + T(0) + T('n-1') + T(1) + T('n-2') + ... + T('n-1') + T(0)

The sum 1/'n' + 1/('n-1') + ... + 1/1 is the harmonic series, which is known to be approximately ln('n'). Therefore, we have:

E[T(n)] = 'n' * ln('n') + T(0) + T('n-1') + T(1) + T('n-2') + ... + T('n-1') + T(0)

Simplifying further:

E[T(n)] = 2 * 'n' * ln('n') + 2 * (T(0) + T(1) + ... + T('n-1'))

Since T(0) + T(1) + ... + T('n-1') is the total running time of quicksort on an array of size 'n', we can replace it with T(n):

E[T(n)] = 2 * 'n' * ln('n') + 2 * T(n)

(d) To prove that 'n'log'k' < 'n'^2log'n' - 'n'^2, we can substitute 'k' = 2, 3, ..., ('n'/2) - 1 and 'k' = 'n'/2, ..., 'n' - 1 separately into the inequality.

For 'k' = 2, 3, ..., ('n'/2) - 1, we have:

'n'log'k' < 'n'^2log'n' - 'n'^2

Dividing both sides by 'n':

log'k' < 'n'log'n' - 'n'

Adding 'n' to both sides:

log'k' + 'n' < 'n'log'n'

Taking the exponent of both sides:

'k' * e^'n' < e^('n'log'n')

Simplifying:

'k' * e^'n' < 'n'^'n'

For 'k' = 'n'/2, ..., 'n' - 1, we have:

'n'log'k' < 'n'^2log'n' - 'n'^2

Dividing both sides by 'n':

log'k' < 'n'log'n' - 'n'

Adding 'n' to both sides:

log'k' + 'n' < 'n'log'n'

Taking the exponent of both sides:

'k' * e^'n' < e^('n'log'n')

Simplifying:

'k' * e^'n' < 'n'^'n'

Therefore, we have shown that 'n'log'k' < 'n'^2log'n' - 'n'^2 for 'k' = 2, 3, ..., ('n'/2) - 1 and 'k' = 'n'/2, ..., 'n' - 1.

(e) Using the inequality from part (d), we can substitute it into the equation derived in part (c) to show that the recurrence yields ET(n)] = O('n'log'n').

From part (c), we have:

E[T(n)] = 2 * 'n' * ET() + 2 * T(n)

Using the inequality 'n'log'k' < 'n'^2log'n' - 'n'^2 from part (d), we can replace ET() with 'n'log'n' to obtain:

E[T(n)] < 2 * 'n' * 'n'log'n' + 2 * T(n)

Simplifying:

E[T(n)] < 2 * 'n'^2log'n' + 2 * T(n)

Since T(n) is the running time of quicksort on an array of size 'n', it is a constant multiple of 'n'log'n'. Therefore, we can replace T(n) with c'n'log'n' for some positive constant 'c':

E[T(n)] < 2 * 'n'^2log'n' + 2 * c'n'log'n'

Combining like terms:

E[T(n)] < (2'n'^2 + 2c'n')log'n'

Since 'n'^2 dominates c'n' for sufficiently large 'n', we can drop the term 2c'n':

E[T(n)] < 2'n'^2log'n'

Therefore, we have shown that the recurrence in part (c) yields ET(n)] = O('n'log'n').


原文地址: https://www.cveoy.top/t/topic/plJ5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录