Quantcast
Channel: Active questions tagged expected-value - Mathematics Stack Exchange
Viewing all articles
Browse latest Browse all 1310

Extending Quicksort's $\mathcal{O}(n \lg n)$ Bound to Duplicated Elements

$
0
0

This is the final part of Problem 7-2 of CLRS'Introduction to Algorithms. The exercise asks to modify the argument given in the text so that the $\mathcal{O}(n \lg n)$ bound also applies to arrays $A$ with duplicated elements. Denote the distinct elements of $A$ by$$z_1 <z_2<\dots<z_m , \quad m \leq n.$$I have managed to show that the total runtime of quicksort is $\mathcal{O}(m+X)$ where $X$ is the number of element comparisons performed.To get the expected runtime I need a bound on $\mathbf{E}[X]$. In the non-duplicated case, the authors used a decomposition into indicators$$ X = \sum_{i=1}^{n-1} \sum_{j=i+1}^n X_{ij}$$where $X_{ij}=I\{ z_i \text{ is compared with } z_j\}$, and$$\mathbf{E}[X_{ij}] = \frac{2}{j-i+1} $$In the duplicated case I got$$X = \sum_{i=1}^{m-1} \sum_{j=i+1}^m X_{ij}, \\\mathbf{E}[X_{ij}] = \frac{\#\{A=z_i\} + \#\{A=z_j\}}{ \sum_{k=i}^j\#\{A=z_k\}}.$$

A simple scaling by the length of the array gives an expression involving the proportion of each distinct value

$$\mathbf{E}[X]=\sum_{i=1}^{m-1} \sum_{j=i+1}^m \frac{p_A(z_i)+p_A(z_j)}{\sum_{k=i}^j p_A(z_k)} $$I can see how this reduces to the book's proof if each value is unique, but I cannot see how to get the log-linear bound in the general case. I've tried treating this as an optimization problem with constraints, but that appears to go nowhere.

I would greatly appreciate help in showing $\mathbf{E}[X] = \mathcal{O}(n \lg n)$.


Viewing all articles
Browse latest Browse all 1310


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>