Computers and Technology, 05.08.2020 05:01, PolinaZagorodniy123
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;
}
Answers: 2
Computers and Technology, 23.06.2019 04:20, RandomLollipop
Which network media uses different regions of the electromagnetic spectrum to transmit signals through air? uses different regions of the electromagnetic spectrum to transmit signals through air.
Answers: 2
Computers and Technology, 23.06.2019 18:30, emmaishere69
List 3 items that were on kens resume that should have been excluded
Answers: 1
Computers and Technology, 24.06.2019 16:30, officialrogerfp3gf2s
Pressing the backspace key deletes the text to the of the insertion point. the left or the right?
Answers: 1
In this assignment you need to compare both algorithms in terms of number of "swaps" and "comparison...
Mathematics, 11.10.2019 01:50
English, 11.10.2019 01:50
Chemistry, 11.10.2019 01:50
Mathematics, 11.10.2019 01:50
Mathematics, 11.10.2019 01:50
Social Studies, 11.10.2019 01:50
Chemistry, 11.10.2019 01:50