Question: Problem 3.2 Selection Sort (13 points) Insertion Sort was discussed during the lecture. Selection Sort is similar to Insertion Sort and works as follows. Given

 Problem 3.2 Selection Sort (13 points) Insertion Sort was discussed during

Problem 3.2 Selection Sort (13 points) Insertion Sort was discussed during the lecture. Selection Sort is similar to Insertion Sort and works as follows. Given an array of elements, you always take the current element and exchange it with the smallest element that can be found on the right hand side of the current element. In doing so, you will gradually build up a sorted sequence on the left side (like in Insertion Sort), and in each iteration "attach" the smallest element from the remaining unsorted right side to it. (a) (2 points) Implement Selection Sort. (b) (3 points) Show that Selection Sort is correct (Hint: consider the loop invariant). (c) (3 points) Generate random input sequences of length n as well as sequences of length n that represent Case A and Case B for the Selection Sort algorithm. Case A: the case which involves the most swaps (Hint: it is not a decreasingly ordered array). Case B: the case with the least swaps. Briefly describe how you generated the sequences (e.g., with a random sequence generator using your chosen language). (d) (4 points) Run the algorithm on the sequences from (c) with length n for increasing values of n and measure the computation times. Plot curves that show the computation time of the algorithm in Case A, Case B, and average case for an increasing input length n. Note that in order to compute reliable measurements for the average case, you have to run the algorithm multiple times for each entry in your plot. You can use a plotting tool/software of your choice (Gnuplot, R, Matlab, Excel, etc.). (e) (1 point) Interpret the plots from (d) with respect to asymptotic behavior and constants

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!