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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:30, tfornwalt4390
Melissa needs to add a topic to an email that she will send to her teacher. choose the name of the field where she should type her topic.
Answers: 2
image
Computers and Technology, 22.06.2019 20:10, yqui8767
Assume the existence of a bankaccount class. define a derived class, savingsaccount that contains two instance variables: the first a double, named interestrate, and the second an integer named interesttype. the value of the interesttype variable can be 1 for simple interest and 2 for compound interest. there is also a constructor that accepts two parameters: a double that is used to initialize the interestrate variable, and a string that you may assume will contain either "simple", or "compound", and which should be used to initialize the interesttype variable appropriately. there should also be a pair of functions getinterestrate and getinteresttype that return the values of the corresponding data members (as double and int respectively).
Answers: 2
image
Computers and Technology, 23.06.2019 02:30, chaaaa
People with high self-esteem: accept their strengths and weaknesses. believe that failed experiences are failures of their whole self. feel good about who they are only when they reach total success. need positive external experiences to counteract negative feelings that constantly plague them.
Answers: 1
image
Computers and Technology, 24.06.2019 11:30, nate1808
What does the https: // mean when you type in a website
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 in other subjects:

Konu
English, 08.11.2019 02:31
Konu
Chemistry, 08.11.2019 02:31