Computers and Technology

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;

}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:00, nika0001
When designing content as part of your content marketing strategy, what does the "think" stage represent in the "see, think, do, care" framework?
Answers: 3
image
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
image
Computers and Technology, 23.06.2019 18:30, emmaishere69
List 3 items that were on kens resume that should have been excluded
Answers: 1
image
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
Do you know the correct answer?
In this assignment you need to compare both algorithms in terms of number of "swaps" and "comparison...

Questions in other subjects:

Konu
Mathematics, 11.10.2019 01:50
Konu
Chemistry, 11.10.2019 01:50