CIS 163 |
Sorting |
Summer 2020 |
Objectives:
- Examine the implementation of different sorts
- Evaluate the performance difference between different sorts
Activity
Create and clone this GitHub Classroom repository: classroom.github.com/g/YBglCT48.
This is the same repository as the "big-O" lab with some minor improvements. The
code now includes four methods for generating arrays:
randomIntArray: Generate an array containing primitive Javaints in random order.randomIntegerArray: Generate an array containing JavaIntegerwrapper objects in random order.orderedIntArray: Generate an array containing primitive Javaints in ascending order.orderedIntegerArray: Generate an array containing JavaIntegerwrapper objects in ascending order.
Be sure to take note of the difference between the "*IntArray" and "*IntegerArray" methods.
You will need the "Integer" versions for methods that use generics.
- Implement a selection sort.
- Predict whether your selection sort will run faster when the input array is already sorted? Why or why not? If faster, will it be the same complexity class (i.e., same "big-O")?
- Use the
measureRunningTimemethod from the "big-O" lab to measure the running time of your selection sort using arrays of random values. - Now measure the running time of your selection sort using an array of already sorted values as input. (In other words, see how long it takes to "sort" an already-sorted list.)
- Was your prediction from #2 correct?
- Implement an insertion sort.
- Will your insertion sort run faster if the input array is already sorted? Why or why not? If faster, will it be the same complexity class (i.e., same "big-O")?
- Measure the running time of your insertion sort using an array of random values as input.
- Measure the running time of your insertion sort using an array of already sorted values as input.
- Was your prediction from #7 correct?
- Implement a merge sort.
- Implement a quick sort.
- Measure and compare the running time of mergesort and quicksort. (Present your findings as "speedup":
mergesort_time/quicksort_time.) - Do mergesort and quicksort appear to have the same big-O? If not:
- Explain why your implementation of mergesort does not have the expected big-O.
- Fix the code.
- Measure and compare the running time of your quicksort with that of the algorithm used by
Arrays.sort. (Present your findings as "speedup":your_quicksort_time/Arrays.sort_time.) - How large of an array can you sort in one minute using a selection sort?
- How large of an array can you sort in one minute using quicksort?
- Implement one of your sorts using the
Comparatordesign discussed in Section 18.4
Submission
Copy your lab report into the git repository and commit. If you worked with a partner, be sure both names are in a comment at the head of each file.Updated Wednesday, 8 July 2020, 6:31 PM