Question: Implement and analyse sorting algorithms. Define a Vehicle class, which stores a vehicle's manufacturer, model, type (sedan, coupe, SUV, truck .etc), cost and current mileage.
Implement and analyse sorting algorithms.
Define a Vehicle class, which stores a vehicle's manufacturer, model, type (sedan, coupe, SUV, truck .etc), cost and current mileage. The class should be defined so that objects of this type can be compared for sorting purposes. Objects should also be able to print their current state in a human understandable format.
Define a sort(lst, alg) function where lst represents a list containing only Vehicle objects and alg is a function which sorts the list according to a given criteria (one of Vehicle's fields). This allows the sort routine used to be configurable by the caller (The Strategy design pattern achieves a simliar goal via subclassing). The function will return a sorted copy of the original list.
Define the following sorting algorithms. (Note: you are not allowed to use pre-defined libraries. Source code must be included. It is acceptable (and suggested) that you use implementations that are freely available on the Internet. Any code that you have not written yourself must be cited and original author must be identified in the source code)
selection sort
merge sort
bubble sort
Write a program which you will use to conduct your experiments. In the main() method, you should create a configurable number of Vehicle objects and place them into a list via comprehension. The objects must be populated with random data. You will invoke one of the sort routines (specified above) and print the sorted array.
Measure the performance of the sorting algorithms. Test with a varied set of list sizes. Graph your results to show how execution time varies as the list size increases.
Summarize your results in a separate written document. It should describe how the various sort algorithms work and explain the experiment's results.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
