subject

In this assignment you need to compare both algorithms in terms of number of "swaps" and "comparisons". Steps to follow:

- Define two arrays with 8K and 16K items. Let's assume the first is A8K, and second on is A16K. Both arrays will be randomly fill out with numbers between -5000 and +5000.

- Sort both arrays with selection sort and report how many "swaps", and "comparisons" are done within each arrays.

- Sort both arrays with insertion sort and report how many "swaps", and "comparisons" are done within each arrays.

Make sure that both algorithms sort same array. For instance, randomly created A8K has an exact copy, A8K2, so that selection sort will be run on A8K while insertion sort will be test on A8K2.

// 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; // compare

swap(A, i, min); // swap

} // Insertion sort

for (int i = 0; i < N; i++)

{

for (int j = i; j > 0; j--)

if ( small(A[j], A[j-1]) == true) // compare

swap(A, j, j-1); // swap

else break;

}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 20:00
How much current flows through the alternator brushes? a. 2–5 a b. 25–35 a, depending on the vehicle c. 5–10 a d. 10–15 a
Answers: 2
question
Computers and Technology, 24.06.2019 00:40
What social factors affect your health
Answers: 3
question
Computers and Technology, 24.06.2019 06:50
What are the things you are considering before uploading photos on social media?
Answers: 1
question
Computers and Technology, 24.06.2019 12:50
When is it most apprpriate for a development team to change the definition of done
Answers: 1
You know the right answer?
In this assignment you need to compare both algorithms in terms of number of "swaps" and "comparison...
Questions
question
Mathematics, 10.02.2021 05:50
question
Mathematics, 10.02.2021 05:50
question
Mathematics, 10.02.2021 05:50
question
Arts, 10.02.2021 05:50
question
Mathematics, 10.02.2021 05:50
Questions on the website: 13722363