代写Assignment 8代做留学生Matlab编程

Assignment 8

Available after Mar 29 at 4pm

This assignment is to completed individually. Please review the standards for academic integrity in the syllabus.

This assignment asks you to implement the quicksort algorithm. Then it asks you to generate some data about the performance of the insertion sort, quicksort and mergesort algorithms and create a hybrid sort.

Note: You are allowed to work on these programs on your local computer. However remember to make sure that your programs work correctly on the Khoury Linux machines. We will be grading your assignments on those machines only!

1 Quicksort

Implement the quicksort algorithm to sort an array of integers in non-descending order. Your implementation should have the following characteristics:

1.   It should choose the pivot randomly between the stated range of indices. For each time the quicksort algorithm is invoked to sort an array, it should set the seed for C's random number generator to 200.

2.   You may choose to implement either Hoare's or Lamuto's partitioning scheme.

3.   The function should have the prototype: void quicksort(int *A,int size) in a file named quicksort.h and implemented in quicksort.c .

Write tests for this algorithm in tests_quicksort.c. You are required to test the above function, but not any helper functions (e.g. the partitioning function).

2 Mirror Mirror on the Wall, Who's the Best Sort of them All?

We have learned about several sorting algorithms. It is time to see the practical performance of these algorithms, especially relative to each other. This will allow us to monitor which sorting algorithm practically works best, for random data of different sizes.

2.1 Preparation

You should start by preparing the following:

4.   Implement the in-place insertion sort algorithm as void insertionsort(int *A,int size) in

insertionsort.h and insertionsort.c . No tests are expected, but you should probably write your own to verify that your code works.

5.   Implement the mergesort algorithm (you can choose any one of top-down or bottom-up) as void mergesort(int *A,int size) in mergesort.h and mergesort.c . You may choose to use your earlier implementation and change it accordingly for this purpose.

6.   All sorting algorithms should sort in non-descending order.

7.   Write a helper function that generates random data for you: int *random_data(intn) that creates and returns an array of size n of random numbers. This will help you to quickly generate data of the required sizes. You can put this function in an appropriately chosen file.

Verify that the helper function works, and each of the sorting algorithms themselves work correctly before proceeding.

2.2 Data Generation

In this part, you should incorporate the logger provided to you earlier to measure the number of operations in each sorting algorithm. Here is the cost model you should use:

•    Each arithmetic operation on one or two integers costs 1 (e.g. add, subtract, multiply, divide, mod, etc.)

•    Each arithmetic comparison on one or two integers costs 1 (e.g. greater than, equal to, not equal to, etc.)

Each assignment between numbers costs 1

Each call to a function (excluding what the function does) costs 2

A return statement costs 1

Any other operation not covered above should cost 1

Incorporate the logger using pre-compiler directives so that it is possible to disable the logger when needed through conditional compiling.

Now generate data about the cost of each sorting algorithm to sort random data of various sizes. Keep in mind the following:

•    For a given size, make sure that you use the same data as input to all sorting algorithm. That way you can directly compare them to each other.

•    For a given size, make sure you try several sets of random data to minimize the bias of the data on the sorting algorithm. Try at least 5 sets for each size.

•    Be careful about the sizes you use. Make sure to sample small sizes well (i.e. don't jump from 2 to 500), and also make sure to include some large sizes (500000 or more).

Tabulate the costs for each sorting algorithm across different sizes. For 5 extra credit points , plot the costs as line graphs (size of array vs cost for each algorithm), so that you can compare the performance more easily!

You may choose to use Excel or any other program for the actual data tabulation and graphing.

For this part, your submission should include (at least):

8.   The code that sets up the data generation. Note that you can set up most of the above in a program, so that you don't have to actually run the program manually several times to capture all the data. You are a programmer now: why do manual work when you can automate! You do not have to write tests for this code itself, but your code should be commented, and should be free of memory leaks.

9.   A PDF document that briefly explains how you generated the data, a table of cost of each algorithm per size of the array, and finally your conclusions about which sorting algorithm is the best. Please put your conclusions in a clearly separated section, so that a reader does not have to read the entire explanation to hunt for your conclusion. Note that you do not have to conclude that one algorithm is the best of them all (chances are, it won't be!). Your conclusion must be supported by the data and a justification by you.  You can include the graphical plot(s) if you are attempting the extra credit.

3 A Hybrid sort

You may find that the mergesort algorithm takes more time than insertion sort for smaller arrays (if you do not find this in your data, you may not have enough samples of small sizes!). It may be advantageous to take a hybrid approach to sorting:

10.Start with mergesort

11.When the sub-array size becomes "small enough", switch to insertion sort to sort only that sub-array instead of continuing with mergesort.

Note that the algorithm is dynamic: it chooses to switch to insertion sort in the middle of sorting an array. This is different from choosing one algorithm or the other at the very beginning by looking at the size of the overall array. For example, the original array may be of size 10000, and yet sorting it may invoke insertion sort at several places.

The tricky part is knowing "when" to switch to insertion sort. You can use your samples from the earlier part (or generate more) to empirically determine the crossover point.

This will be a size of the input below which insertion sort is faster than mergesort, but above which mergesort is faster than insertion sort. Please note that due to sampling and randomization, you may not find a clear crossover point. But we don't need to be very accurate, so choose a point above which mergesort clearly wins.

To implement the hybrid sort, you may have to follow these steps:

12.Write a version of insertion sort with this prototype: void insertion_sort(int *A,int left,int right) . This version only sorts the array A[left..right] (indices included).

13.Write a new version of the hybrid mergesort: void hybrid(int *A,int size) , and its corresponding helper functions. This uses the mergesort algorithm normally, but switches to the above insertion sort for all sub-arrays of sizes at or below your crossover point.

With this in place, re-run the data generation from the earlier section for this hybrid. Now tabulate the results comparing only pure mergesort, and this hybrid mergesort.

For this part, your submission must include:

14.Your implementation of the hybrid sort, divided into files suitably.

15.The PDF document with the extra tabulated data, along with a brief discussion of how  you chose the crossover point and your conclusions from the data you generated. This does not have to be in a separate PDF file, but you may choose to separate this into another section .

After completing this part, you would have created your own hybrid sort!

What to Submit

Please submit the following:

Source code, suitably styled and commented.

Tests for the quicksort algorithm only.

A PDF document with all the details mentioned above.

The autograder for this assignment will only check for your quicksort implementation.

This means that there is no help to determine if your code works correctly, nor will the server flag any missing files! Please make sure your submission is complete.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图