Assignment#1 (2024)
Assignment#1 (2024)
Assignment#1 (2024)
Instructions:
• Implement the different sorting algorithms given in the question part using C++, Java or Python
programming language.
• Submit a soft copy (both source codes and report) in a zipped file before the stated deadline.
• Submission after the stated deadline is not acceptable, even with any excuse.
• In the implementation make sure that the files are organized in a reasonable way, and that it
does not require a wizard to make the implementation work outside your personal environment.
Questions :
2. Merge Sort
3. Heap Sort
4. Quick Sort
5. Selection Sort
The testing parameters for the algorithms that shall be used are:
• values start and stop that determine the minimum and maximum number of entries to be sorted,
• a value steps that determines into how many intervals the range from start to stop shall be
divided (see Figure 1 for an example where start = 0, stop = 2, 000, 000, presortedness =
0.5 and steps = 100000), and
1
Figure 1: Sample test output.
In addition, there should be a constant (that can of course be altered) called rep.
• It determines how many times the sorters are run on arrays of each size (with different array
contents as input, of course). This number should not be too small, in order to make the tests
less prone to random fluctuations caused by an unlucky choice of input data.
The implementation should be done in such a way that that the running times of the sorters are
measured as accurately as possible. In particular, pay attention to the following:
2
• Search for good ways to measure elapsed time in the programming language of your choice.
Select the one which is most suitable and make a few tests to ensure that it works as expected.
• Avoid unnecessary memory allocation, especially repeated allocation of large input arrays. In-
stead, use and re-use sufficiently large arrays.
• For the sake of fairness, let all sorters run on the same input arrays, i.e., populate an array with
random integers and apply all sorters to these data before turning to the next round. (Obviously,
you need two arrays for this, one holding the original data and a copy to which the sorters are
applied.)
• During your test runs, try to make sure that the workload caused by other processes in your
computer is as low as possible.
In addition, take the following points into consideration when implementing the algorithms
• Note that textbook psuedocode versions sometimes can be tuned a bit, as they sometimes trade
efficiency for conciseness of the description.
• If the tests reveal a strange behavior of some or all sorters, study your implementation to find
the reason and improve it.
Finally, prepare a report which discus’s whether the results of the implementations confirm your
expectations and coincide with the theoretical results. If you discover discrepancies, try to reason out
why it occurred.