Here are some resources to help you with this pset:
- Mike Menne's Strategy Pattern video
- CS50 study contains information about various sorting algorithms
- Timing execution in Java
For this problem set, you will be using the Strategy Design Pattern as well as getting a feel for various sorting algorithms.
First, create a SortStrategy interface. This interface should be very simple!
Then, create an ArraySorter class. This class should also be fairly simple - it needs to include a method that accepts a SortStrategy object.
You should then write a few classes that implement the SortStrategy interface. Recall that you worked on sorting in CS50, so you can adapt those examples to suit your needs.
Try to incorporate at least one sorting algorithm that is O(n^2) (like bubble, insertion, or selection sort), and one that is O(n log n) (like mergesort). Write tests for your sorting algorithms to ensure that they work properly.
Finally, it is time to put your sorting strategy to work. Create a few example arrays, then sort them using all of your strategies. You should time your sorts and print out the execution times once the sorting is finished.
Which sorting algorithm is the most efficient? How does the starting point of the array affect the amount of time it takes to sort? Which array takes the shortest amount of time to sort? The most amount of time?
#If you have time
Incorporate the OutputStrategy from lecture to allow the user to output the results to the console or to a file.