代写Computer Programming、代做CS/python、代做sorting algorithms、java/c++设计代做代做P

Computer Programming 2 Assignment 3Assignment 3: Sort WarsCore Questions (5 marks each)TaskIf quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mentionit? For that matter, why are there so many sorting algorithms?Your mission (should you choose to accept it) is to investigate these and other questions in relationto the algorithms selection sort, insertion sort, merge sort, and quicksort.1. Explain each of the algorithms in a way that would be understandable to an intelligent layperson. You should not use any code (or even pseudo code) in your explanation, but you willprobably need to use general concepts such as compare and swap, and youll certainlyneed to use procedural words such as if and repeat.You might find it helpful to consider an algorithm as if it were a game for which you need todefine the rules. For example, heres how you could describe the bubble sort algorithm as if itwas a solitaire game played with a deck of cards that contain the values to process.2. Write a set of guidelines for helping someone decide which sort algorithm would be mostappropriate for a particular situation. Include in your guidelines a description of theadvantages and disadvantages of each algorithm, together with an indication as to why thosecharacteristics apply. Your goal is to provide enough information so that someone not familiarwith the details of each algorithm would be able to decide which algorithm is right for them.For example, if someone was considering using counting sort, then the following briefinformation could help decide if it was appropriate.Flinders University / College of Science and Engineering 1Bubble TroubleThe playing area consists of several regions: foundation, tableau, stock, and discard.Initially, all cards are in the stock.Play consists of a number of rounds. To begin a round, place the top card of thestock face up in the tableau, then turn over the next card. If the stock card is smallerthat the tableau card, place it face down on the discard pile; otherwise, place thetableau card on the discard pile and the stock card in the tableau. Play the remainingstock cards in the same way, then move the final tableau card (which will be thelargest of the stock cards) to the foundation and use the discard pile as the new stock.This completes one round.Continue to play rounds until the stock is exhausted. The cards in the foundationwill now be sorted with the smallest card on top.Computer Programming 2 Assignment 3Extension Questions (5 marks each)BackgroundIn this section, youll need to be able to measure the speed of execution of parts of your code. On aUnix system, you can measure how much time a section of code takes by calling the systemfunction getrusage before and after that section. The function returns information about variousaspects of resource usage, including the amount of system time (time taken by system routines thatyou call) and the amount of user time (time taken by your own code). Note that this is process time,not wall-clock time, so its an accurate measure even if the system is busy executing otherpeoples code as well. Consult the man page for getrusage if you need more information.#include int main() { struct rusage before, after; // for recording usage stats // prepare the data getrusage(RUSAGE_SELF, &before); // execute the code you want to time getrusage(RUSAGE_SELF, &after); int secs = after.ru_utime.tv_sec - before.ru_utime.tv_sec; int usecs = after.ru_utime.tv_usec - before.ru_utime.tv_usec; cout }Algorithm Counting SortDescription ? Count the number of times each different value appears, thenoverwrite the values in lowest-to-highest order, with each valuerepeated according to the counts.Advantages Usually faster than any of the comparison-based sorts. Algorithmiccomplexity is O(n + k), irrespective of data order, where n is the listlength and k is the number of distinct values th代写Computer Programming作业、代做CS/python作业、代做sorting algorithms作at might occur. Typicalcase is where k Simple to code.Disadvantages ? Only usable where the values to be sorted can be used to index anarray of value counts, which usually means the values are integersover a small range. In other words, the algorithm cant be used to sortcommon non-integral values such as strings and floats, and itsinappropriate even for integers if the range of values is large. Requires an auxiliary array (to store the counts) of size equal to thenumber of different possible sort values. If the range of values islarge, the cost of allocating and maintaining this array could besignificant.When to use If your circumstances allow, its hard to beat this algorithm. Butbecause it places very tight restrictions on the nature of the data tosort, you will often have to choose another approach.Flinders University / College of Science and Engineering 2Computer Programming 2 Assignment 3TaskPractical sort implementations usually combine more than one sorting algorithm, attempting to takeadvantage of the best characteristics of each. For example, a straightforward but effective approachfor general-purpose sorting is to use quicksort, but with a switch-over to insertion sort when the sizeof the lists that result from the partitioning falls below a threshold value. The structure of thecombined sort would be like this:sort (...) { if size is less than threshold { do an insertion sort } else { // do a quicksort partition recursively sort the first part recursively sort the second part }}This approach is generally faster that using pure quicksort because insertion sort has a loweroverhead than quicksort and is thus faster, provided the length of the list is small enough. To get thegreatest speedup, the threshold for switching to insertion sort needs to be carefully chosen: toolarge, and the greater algorithmic cost of the insertion sort will overwhelm any lower overheads; toosmall, and the potential benefits of the combined approach are wasted.3. Design an experiment to determine the best cutover threshold size for the combinedquicksort-plus-insertion-sort implementation. Youll need to consider a range of data sizes,including both random and worst-case data sets.Write a program that could be used to perform the experiment. Youll need to provide the sortcode itself (use your code from prac 5) as well as a suitable main function for testing it (adaptthe main function from prac 5).Your experimental design should be sufficiently detailed that you could hand the task over toa tester who is not familiar with sorting algorithms or even with programming. Ideally, thetester should only need to run the program under specified conditions and record the results.4. Run your experiment and report on the findings. Your report should include the data yougather, an analysis of that data, and a clear recommendation as to the best cutover threshold.Consider how best to present your results. Youll certainly want to tabulate the data, but youmight also find it helpful to plot it as well. Because the actual times will be heavily dependenton the data size, you might find it useful to normalise the times against the ideal time (bydividing by n log n) before plotting them.AssessmentPairingThis assignment must be done individually.ScoringSubmit written material as PDF reports to the appropriate handins on FLO. The core score will bebased on your answers to the 2 core questions, and the extension score will be based on youranswers to the 2 extension questions.Your answer for each question should be between 300 and 600 words (half to 1 typed page),excluding code listings (where appropriate), which should be as an appendix in your report. YourFlinders University / College of Science and Engineering 3Computer Programming 2 Assignment 3submission should conform to accepted practices for academic writing. Of course, you must giveappropriate acknowledgement to any material that you use or reference. 转自:http://ass.3daixie.com/2018103013869491.html

你可能感兴趣的:(代写Computer Programming、代做CS/python、代做sorting algorithms、java/c++设计代做代做P)