0% found this document useful (0 votes)
206 views4 pages

Randomized Quicksort Performance Analysis

This paper analyzes the performance of a randomized Quicksort algorithm. It begins with introductions to randomized algorithms and sorting algorithms in general. It then describes the basic Quicksort algorithm and how randomizing the choice of pivot at each step improves the worst-case running time from O(n^2) to an expected O(n log n). Through an analysis of the number of element comparisons, it is shown that by randomly selecting the pivot, no subset of elements will grow to more than 3/4 of the total size with high probability. This randomization results in faster overall performance compared to always choosing the leftmost element as the pivot.

Uploaded by

Wlad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
206 views4 pages

Randomized Quicksort Performance Analysis

This paper analyzes the performance of a randomized Quicksort algorithm. It begins with introductions to randomized algorithms and sorting algorithms in general. It then describes the basic Quicksort algorithm and how randomizing the choice of pivot at each step improves the worst-case running time from O(n^2) to an expected O(n log n). Through an analysis of the number of element comparisons, it is shown that by randomly selecting the pivot, no subset of elements will grow to more than 3/4 of the total size with high probability. This randomization results in faster overall performance compared to always choosing the leftmost element as the pivot.

Uploaded by

Wlad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Author name: Sulea Vlad 

  Group: 242  
 
 
R3. Randomized Quicksort Performance Analysis 
 
 
Abstract  
 
This paper is derived from a series of other papers and studies on randomized algorithms.  
The  purpose  of  the  paper  is  to  offer  a  brief  introduction  about  the  nature  of  randomized 
algorithms,  the  range  of  their  applications,  the  principles  underlying  their construction and to 
analyze the performance of a randomized Quicksort algorithm. 
 
1. Introduction 
 
One of the fundamental questions of science is whether randomness really exists or whether 
term randomness is used only to deal with the laws of events which we do not fully 
understand. Two early views are ”The randomness is the unknown and the nature is 
determined in its fundamentals” (Democritos 470-404 BC).  
Randomness as a mathematical topic has been studied since 17th century. There were several 
attempts to formalize chance by mathematical laws, but there is no proof that perfect 
randomness exists in the real world, more exactly there is no proof that quantum mechanical 
phenomena of the microworld can be exploited to provide a perfect source of randomness for 
the macroworld. 
 
Randomized algorithms are such algorithms that make random choices during their 
executions. As a consequence, their outcomes do not depend only on their external inputs.  
A randomized algorithm is one that receives, in addition to its input data, a stream of random 
bits that it can use for the purpose of making random choices. Even for a fixed input, different 
runs of a randomized algorithm may give different results. As a result in most of the cases the 
the description of a randomized algorithm will involve a probabilistic statement.  
 
The importance of the randomized algorithms is increasing. There are several reasons why the 
researchers put effort into this field. Randomized algorithms are often faster either from the 
worst-case asymptotic point of view or from the numerical implementation point of view, they 
are often simpler than deterministic ones for the same problem, they have easily interpretable 
outputs, this fact being important in applications where the analyst’s time rather than just 
computation time is of interest. Randomized algorithms have been recently surprisingly 
successful when dealing with huge-data matrix computation problems 
 
2. Sorting Algorithms 
 
In Computer Science, a sorting algorithm is an algorithm that puts elements of a list in a 
certain order, more precisely, is an algorithm made up of a series of instructions that takes an 
array as an input, performs specified operations, and outputs a sorted array. The most used 
order are numerical order and lexicographical order. Efficiency is very in sorting. 
 
There are sorting algorithms that have a large gap between their performance “on average” 
and their performance in the worst case. Sometimes in this case we can improve the 
worst-case performance by actually adding randomization into the algorithm. On classic 
example of this is the Quicksort algorithm. 
 
Quicksort problem statement:  
 
● Input​: An array S of n elements, 
● Output​: A permutation of the input such that S[i] <= S[i+1], i= 1, … , n-1. 
 
 
Quicksort algorithm:  
 
1. Pick an element p of the array as the pivot(or halt if the array has size 0 or 1). 
2. Split the array into sub-arrays LESS, EQUAL, and GREATER by comparing each element 
to the pivot.  
3. Recursively sort LESS and GREATER. 
 
The above algorithm is not yet fully specified because we have not stated how we will pick the 
pivot element p.  
 
Basic Quicksort: ​Run the Quicksort algorithm as given above, always choosing the leftmost 
element in the array as the pivot. 
We will observe that the running time is O(n^2) on any array of n elements, this being the 
worst case running time, because Step 1 can be executed at most n times, and Step 2 takes at 
most n steps to perform. 
 
Randomized Quicksort: ​Run the Quicksort algorithm as given above, each time picking a 
random element in the array as the pivot. 
 
We will prove that for any given array input array S of n elements, the expected time of this 
algorithm E[T(I)] is O(n log n). 
 
 
 
 
3. Analysis of Randomized Quicksort 
 
Analysis of the number of comparisons: T(n) 
 

 
 
In case we can find y in cn steps for some constant c. 
 
Solution of the above inequality:  
 

 
 
Asymptotically, the same solution is obtained if we require only that none of the sets S1, S2 
has more than 3/4 n elements. Since there are at least n/2 elements y with the last property 
there is a good chance that if y is always chosen randomly, then we get a good performance.  
 
Let the set S to be sorted be given and let  
si – be the i-th smallest element of S; sij – be a random variable having value 1 if si and 
sj are being compared (during an execution of the RQS).  
 
Expected number of comparisons of RQS 

 
If pij is the probability that si and sj are being compared during an execution of the algorithm, 
then E[sij] = pij.  
 
In order to estimate pij it is enough to realize that if si and sj are compared during an 
execution of the RQS, then one of these two elements has to be in the subtree headed by the 
other element in the comparison tree being created at that execution. Moreover, in such a 
case all elements between si and sj are still to be inserted into the tree being created.  
 
 
 
 
 
 
Therefore, at the moment other element (not the one in the root of the subtree), is chosen, it 
is chosen randomly from at least |j − i| + 1 elements. Hence pij ≤ 1 |i−j|+1 . Therefore we 
have (for Hn = Pn i=1 1 i ) 
 

 
4. Conclusions 
 
By now it is recognized that, in a wide range of applications, randomization is an extremely 
important tool for the construction of algorithms. Randomized algorithms proved to be in 
most of the cases a good decision. In many situation it was shown that the complexity of 
algorithms is improved using randomization.  
 
 
References 
 
https://ac.els-cdn.com/0166218X9190086C/1-s2.0-0166218X9190086C-main.pdf?_tid=5118b808-f7d6-11
e7-bbbf-00000aacb35e&acdnat=1515788740_8f97a29af2681a8e61c84ce61fee6fd3 
 
https://www.cs.cmu.edu/~avrim/451f11/lectures/lect0906.pdf 
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.107.8482&rep=rep1&type=pdf 
 
http://community.wvu.edu/~krsubramani/courses/fa01/random/lecnotes/lecture2.pdf 
 
https://www.fi.muni.cz/usr/gruska/random15/random1501.pdf 
 
https://www.sciencedirect.com/science/article/pii/0166218X9190086C 

You might also like