Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE 374: Algorithms I

Coding Homework #1 Insertion sort

Grading Rubric:

1.   The program submitted for this homework must pass the necessary base case test(s) in order to qualify for earning any score at all. Programs that do not meet base case requirements will be assigned zero!

2.   The code should be well formatted and commented on. The basic requirement is the code is understandable for a person who has basic coding knowledge.

3.   There is some additional test case will be used for grading. Your code must complete it correctly and efficiently.

4.   To earn the point, you must use insertion sort to finish this assignment.

Requirements:

In this part of the exercise, you will be submitting the modified starter code Solution.java via Canvas CODE plug-in.

If this is your first time using the CODE plug-in then review the submission process via the following brief video demonstration -- https://youtu.be/P2bWUt5KqbU.

Please use insertion sort to sort the array L, and output the N-th move of the array. (N can be smaller than or equal to the the maximum steps needed to sort the array)

First, you need to do the insertion sort for the array L and record the result for each movement. Consider we make screenshots for each movement during the insertion sort process. Then, in the second step, select the N-th movement and show it as the output. The following websites   (apart from the video lectures) may help you with the Insertion sort:

1.   https://www.hackerearth.com/practice/algorithms/sorting/insertion-sort/visualize/

2.   https://visualgo.net/en/sorting?slide=8

Example 1:

Input: L = 12, 11, 13, 5, 6; N = 1

Output: 11, 12, 13, 5, 6

Explanation:

Step 1: Sort this array and record each step of transformation:

[ 12, 11, 13, 5, 6], [11, 12, 13, 5, 6], [ 11, 12, 5, 13, 6], [ 11, 5, 12, 13, 6], [5, 11, 12, 13, 6], [5, 11, 12, 6, 13], [5, 11, 6, 12, 13], [5, 6, 11, 12, 13]

Step 2: Select the output at N=1 (i.e., what does the array look like after the first transformation): [11, 12, 13, 5, 6]

Note: For the original array [12, 11, 13,5,6], you need to use the insertion sort to finally      turn the array into [5,6, 11, 12, 13]. If you correctly apply the algorithm, it would take a total of 7 steps to transform the original array to get the desired outcome.

Example 2:

Input: L = 12, 11, 13, 5, 6; N = 6

Output: 5, 11, 6, 12, 13

Explanation: All the moves to sort this array are listed below:

[ 12, 11, 13, 5, 6], [ 11, 12, 13, 5, 6], [ 11, 12, 5, 13, 6], [ 11, 5, 12, 13, 6],

[5, 11, 12, 13,6],[5, 11, 12,6, 13],[5,11,6,12,13],[5,6, 11, 12, 13]

Example 3:

Input: L = 250, 343, 137, 789, 551, 954; N = 2

Output: 137, 250, 343, 789, 551, 954

All the moves to sort this array are listed below:

[250, 343, 137, 789, 551, 954], [250, 137, 343, 789, 551, 954],

[137, 250, 343, 789, 551, 954], [ 137, 250, 343, 551, 789, 954],