1 / 10

Median Finding and Quick Sort

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

rollin
Download Presentation

Median Finding and Quick Sort

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 10000 for all 4 algortihms. • Also changed the group size 3 or 5 for the Linear Median Finding Algorithm.

  10. Thank You! Demo.

More Related