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, 22.06.2019 08:00
Two technicians are discussing the common u-joint. technician a says its input and output speeds should be equal. technician b says that it normally has two yokes. which technician is correct?
Answers: 1
question
Computers and Technology, 22.06.2019 13:50
The instruction ishl (shift left integer) exists in jvm but not in ijvm. it uses the top two values on the stack, replacing the two with a single value, the result. the sec- ond-from-top word of the stack is the operand to be shifted. its content is shifted left by a value between 0 and 31, inclusive, depending on the value of the 5 least signifi- cant bits of the top word on the stack (the other 27 bits of the top word are ignored). zeros are shifted in from the right for as many bits as the shift count. the opcode for ishl is 120 (0x78).a. what is the arithmetic operation equivalent to shifting left with a count of 2? b. extend the microcode to include this instruction as a part of ijv.
Answers: 1
question
Computers and Technology, 22.06.2019 19:10
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
question
Computers and Technology, 22.06.2019 21:30
The graph shows median weekly earnings for full-time workers according to education level. which can you not conclude?
Answers: 2
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, 02.02.2021 08:40
question
Biology, 02.02.2021 08:40
question
History, 02.02.2021 08:40
question
Mathematics, 02.02.2021 08:40
question
Mathematics, 02.02.2021 08:40
question
Mathematics, 02.02.2021 08:40
Questions on the website: 13722367