-
Notifications
You must be signed in to change notification settings - Fork 28
IntroSort
Jinho D. Choi edited this page Sep 14, 2015
·
1 revision
Quicksort runs fast in general but it still cannot avoid the O(n^2) complexity for the worst case. On the other hand, Heapsort runs slightly slower than Quicksort in general but is guaranteed to run in O(n log n) for all cases. Introspective sort (Introsort) is a hybrid between Quicksort and Heapsort that takes advantages of both algorithms. Here is the idea behind Introsort.
- Start performing Quicksort on the input list.
- For each partition, check if its depth is greater than "2 · floor(log2n)".
- If it is, stop Quicksort and start performing Heapsort.
- If it is not, keep performing Quicksort.
- Create a class
IntroSort
undersort
. - Extend the
AbstractSort
class. - Define the
sort
method implementing the Introsort algorithm. - Ensure your program runs correctly. I'll perform several unit tests to assess the correctness of your program.
-
QuickSort
,HeapSort
.
- Create lists of 100, 200, ..., 1000 random comparable keys, keys in ascending order, and keys in descending order (you will end up creating
10*3 = 30
lists). - For HeapSort, QuickSort, and IntroSort:
- Measure the time it takes to sort all keys in each list.
- Repeat this procedure 1K times, and sum the times for each algorithm.
-
SortTest#compareSpeeds()
.
- Explain briefly about your implementation of IntroSort.
- Create tables and charts showing the speed comparisons with respect to the nature of the lists and their sizes.
- Write analysis of the speed comparisons given different conditions.
Copyright © 2014-2017 Emory University - All Rights Reserved.