Question: In this activity you need to compare both algorithms' running times (see this) on best, average, worst cases. Steps to follow: Define an int array
In this activity you need to compare both algorithms' running times (see this) on best, average, worst cases.
Steps to follow:
Define an int array with 16,000 elements, and fill with ascending ordered numbers between -20000 and 20000, such as [-19988, -19975, ... 0, ..., 19983, 19989]. Array items are randomly selected. Then, sort this array with selection and insertion sort algorithms. Report corresponding running times.
Define an int array with 16,000 elements, and fill with random numbers between -20000 and 20000. The is no order to observe. Then, sort this array with selection and insertion sort algorithms. Report corresponding running times.
Define an int array with 16,000 elements, and fill with descending ordered numbers between -20000 and 20000, such as [19982, 19979, ... 0, ..., -19980, -19991]. Array items are randomly selected. Then, sort this array with selection and insertion sort algorithms. Report corresponding running times.
Output of your program should be in the following format:
Asc ordered, SS: X sec, IS: X sec Ran ordered, SS: X sec, IS: X sec Des ordered, SS: X sec, IS: X sec
X is number with two-decimal points. See this class example for the formatting hint.
Make sure that both algorithms sort the same array in each subtask.
You can use any code shared on D2L. You need to implement your code using below pseudocodes.
Do not include unnecessary headers and functions. Code syntax will be graded.
Submission Procedure:
Submit a single complete (compiles and runs) .cpp file with the following format: "Lastname_FirstInitial_LastFourDigitsOfCWID_L4.cpp", such as Smith_J_5678_L4.cpp.
| // Selection sort for (int i = 0; i < N; i++) { int min = i; for (int j = i+1; j < N; j++) if ( small(A[j], A[min]) == true) min = j; swap(A, i, min); } | // Insertion sort for (int i = 0; i < N; i++) { for (int j = i; j > 0; j--) if ( small(A[j], A[j-1]) == true) swap(A, j, j-1); else break; } |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
