Median Finding and Quick
Implement the median-finding algorithms –
Random and Linear Median Finding Algorithms.
The user is able to select the “k”, i.e., the rank of
the number desired as output (k = n/2 is the
The user is also able to select groups of 3 or 5 in
the linear-time median finding algorithm.
The user can compare the performance of
Random and Linear Median Finding
Implement quick sort using both
algorithms and compare the performances
of these different versions.
Randomized Median Finding
m = a random element of S is the pivot.
S1 = all numbers in S < m
S2 = all numbers in S > m
if |S1| >= k return Qsel(S1,k);
else if |S| - |S2| >= k return m;
else return Qsel(S2,k-|S|+|S2|);
The difference with this approach is about
the pivot selection.
To find the pivot element, we divide S into
n/5 groups of 5 elements each.
Each group is then sorted and its median is
Then invoke a recursive call to the same
function to find median of medians.
Then this median of medians becomes the
pivot element for the QSel function.
This will find the k-th smallest element in a
sequence S of n elements in worst-case
The project is implemented in java.
The User Interface is done using Java Swing-
This takes a list of numbers, k and number of
elements in a group as input.
4 classes – MedianQuickSort.java,
MedianRandomQuickSort.java, Median.java, and
MedianRandom.java are written.
Used simple counter to measure
Checked performance for varying input
sizes like 100, 1000 and 10000 for all 4
Also changed the group size 3 or 5 for the
Linear Median Finding Algorithm.