-
Notifications
You must be signed in to change notification settings - Fork 28
Timsort
Jinho D. Choi edited this page Sep 7, 2016
·
1 revision
Mergesort gives good average and worst-case complexities, O(n log n), but is slower than Insertion sort for the best-case. Timesort is a hybrid between Mergesort and Insertion sort that takes advantages of both algorithms. Here is the idea behind Timsort.
- Start performing Mergesort on the input list.
- For each partition, check if the size of the partition is smaller or equal to 64.
- If it is, stop Mergesort and start performing Insertion sort.
- If it is not, keep performing Mergesort.
- Create two classes
LastnameTimSort1
andLastnameTimSort2
undersort
. - Extend the
AbstractSort
class. - Define the
sort
method inLastnameTimSort1
implementing the Timesort algorithm using Insertion sort. - Define the
sort
method inLastnameTimSort2
implementing the Timesort algorithm using Shell sort. - Ensure your program runs correctly. I'll perform several unit tests to assess the correctness of your program.
-
MergeSort
,InsertionSort
,ShellSort
.
- 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
MergeSort
,LastnameTimSort1
, andLastnameTimSort2
: - 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
TimSort
. - 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.