Median Finding and Quick Sort Suvarna Angal
Project Requirements 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 median). The user is also able to select groups of 3 or 5 in the linear-time median finding algorithm.
Project Requirements The user can compare the performance of Random and Linear Median Finding Algorithms. Implement quick sort using both algorithms and compare the performances of these different versions.
Randomized Median Finding QSel(S,k) 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|);
Median Finding 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 selected. Then invoke a recursive call to the same function to find median of medians.
Median Finding 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 time O(n).
Implementation The project is implemented in java. The User Interface is done using Java Swing- MedianClient.java 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.
User Interface
Analysis Used simple counter to measure performance. Checked performance for varying input sizes like 100, 1000 and 10000 for all 4 algortihms. Also changed the group size 3 or 5 for the Linear Median Finding Algorithm.
Thank You! Demo.