2023 Assignment 6 Notes Include counts of compares and swaps in all trace tables for | Assignment Collections

Computer Science 2023 A+ Answers

2023 Assignment 6 Notes Include counts of compares and swaps in all trace tables for | Assignment Collections

Assignment 6

Notes:

• Include counts of compares and swaps in all trace tables for each row, and a total count when

done.

• Do all trace tables by hand (don’t write programs to generate them – you will learn more).

Question 1

Do a trace table for selection sort for the following array of numbers: 15 12 16 13 11 14 10 17.

Do a trace table for selection sort for the following array of numbers: 10 11 12 13 14 15 16 17.

What does this say about best case performance of selection sort?

Do a trace table for selection sort for the following array of numbers: 17 16 15 14 13 12 11 10.

What does this say about worst case performance of selection sort?

Question 2

Do a trace table for insertion sort for the following array of numbers: 15 12 16 13 11 14 10 17.

Do a trace table for insertion sort for the following array of numbers: 10 11 12 13 14 15 16 17.

What does this say about best case performance of insertion sort?

Do a trace table for insertion sort for the following array of numbers: 17 16 15 14 13 12 11 10.

What does this say about worst case performance of insertion sort?

Question 3

In this question you will measure the performance of selection sort and insertion sort by plotting N against the average number of comparisons and swaps needed to sort a randomly generated array of N doubles.

Write (static) methods:

• boolean isSorted(double[] a) – returns true if and only if the array a is sorted.

• double[] random(int N) – returns an array of doubles of size N where each entry in the array is

a random double between 0 and 1 (use Math.random()).

• void selection(double[] a) – sorts the array a using selection sort.

• void insertion(double[] a) – sorts the array a using insertion sort.

Instrument your two sorting routines to count the number of compares and swaps each routine does.

Write a main method which, for various appropriate choices of N:

• generates 100 random arrays of size N, calls selection sort on each, checks that each array is

sorted, and outputs the average number of compares per call.

• generates 100 random arrays of size N, calls insertion sort on each, checks that each array is

sorted, and outputs the average number of compares per call.

• You main method should use your isSorted() method to check that each array is sorted after

you have run your sort method.

Do a plot (in Excel, OpenOffice, etc) of N against the number of compares (plot both sorts on the same plot), labeling the axis nicely, etc. Also plot N

Remark:

• Be careful not to sort on an already sorted array (doing so means you are measuring the

worst/best case, and not the average case).

• Strictly speaking you don’t need to generate 100 arrays and average for selection sort since its

best case, worst case and average case all the same.

• Make sure your sorting and instrumentation code is correct before you start measuring the

 

counts and doing the plots!

 

We give our students 100% satisfaction with their assignments, which is one of the most important reasons students prefer us to other helpers. Our professional group and planners have more than ten years of rich experience. The only reason is that we have successfully helped more than 100000 students with their assignments on our inception days. Our expert group has more than 2200 professionals in different topics, and that is not all; we get more than 300 jobs every day more than 90% of the assignment get the conversion for payment.

Place Order Now

#write essay #research paper #blog writing #article writing #academic writer #reflective paper #essay pro #types of essays #write my essay #reflective essay #paper writer #essay writing service #essay writer free #essay helper #write my paper #assignment writer #write my essay for me #write an essay for me #uk essay #thesis writer #dissertation writing services #writing a research paper #academic essay #dissertation help #easy essay #do my essay #paper writing service #buy essay #essay writing help #essay service #dissertation writing #online essay writer #write my paper for me #types of essay writing #essay writing website #write my essay for free #reflective report #type my essay #thesis writing services #write paper for me #research paper writing service #essay paper #professional essay writers #write my essay online #essay help online #write my research paper #dissertation writing help #websites that write papers for you for free #write my essay for me cheap #pay someone to write my paper #pay someone to write my research paper #Essaywriting #Academicwriting #Assignmenthelp #Nursingassignment #Nursinghomework #Psychologyassignment #Physicsassignment #Philosophyassignment #Religionassignment #History #Writing #writingtips #Students #universityassignment #onlinewriting #savvyessaywriters #onlineprowriters #assignmentcollection #excelsiorwriters #writinghub #study #exclusivewritings #myassignmentgeek #expertwriters #art #transcription #grammer #college #highschool #StudentsHelpingStudents #studentshirt #StudentShoe #StudentShoes #studentshoponline #studentshopping #studentshouse #StudentShoutout #studentshowcase2017 #StudentsHub #studentsieuczy #StudentsIn #studentsinberlin #studentsinbusiness #StudentsInDubai #studentsininternational