Presentation is loading. Please wait.

Presentation is loading. Please wait.

Median Finding and Quick Sort

Similar presentations


Presentation on theme: "Median Finding and Quick Sort"— Presentation transcript:

1 Median Finding and Quick Sort
Suvarna Angal

2 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.

3 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.

4 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|);

5 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.

6 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).

7 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.

8 User Interface

9 Analysis Used simple counter to measure performance.
Checked performance for varying input sizes like 100, 1000 and for all 4 algortihms. Also changed the group size 3 or 5 for the Linear Median Finding Algorithm.

10 Thank You! Demo.


Download ppt "Median Finding and Quick Sort"

Similar presentations


Ads by Google