Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Task

If quicksort is so quick, why bother with anything else? If bubble sort is so bad, why even mention it? 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 relation to the algorithms selection sort, insertion sort, merge sort, and quicksort.

Core Questions

1. Explain each of the algorithms in a way that would be understandable to an intelligent lay person. You should not use any code (or even pseudo code) in your explanation, but you will probably need to use general concepts such as "compare" and "swap", and you'll certainly need 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 to define the rules. For example, here's how you could describe the bubble sort algorithm as if it was 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 most appropriate for a particular situation. Include in your guidelines a description of the advantages and disadvantages of each algorithm, together with an indication as to why those characteristics apply. Your goal is to provide enough information so that someone not familiar with the details of each algorithm would be able to decide which algorithm is right for them.

Extension Questions

In this section, you'll need to be able to measure the speed of execution of parts of your code. You can measure how much time a section of code takes by calling the system function getrusage before and after that section. The function returns information about various aspects of resource usage, including the amount of system time (time taken by system routines that you call) and the amount of user time (time taken by your own code). Note that this is process time, not "wall-clock" time, so it's an accurate measure even if the system is busy executing other people's code as well.

Consult the man page for getrusage if you need more information.

Bubble Trouble

The 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 the stock face up in the tableau, then turn over the next card. If the stock card is smaller than the tableau card, place it face down on the discard pile; otherwise, place the tableau card on the discard pile and the stock card in the tableau. Play the remaining stock cards in the same way, then move the final tableau card (which will be the largest 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 foundation will now be sorted with the smallest card on top.

#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 << secs * 1000000 + usecs << endl; // in microseconds

}

Practical sort implementations usually combine more than one sorting algorithm, attempting to take advantage of the best characteristics of each. For example, a straightforward but effective approach for general-purpose sorting is to use quicksort, but with a switch-over to insertion sort when the size of the lists that result from the partitioning falls below a threshold value. This approach is generally faster that using pure quicksort because insertion sort has a lower overhead than quicksort and is thus faster, provided the length of the list is small enough.

The structure of the combined sort would be like this:

sort (...) {

if size is less than some threshold {

do an insertion sort

} else { // do a quicksort

partition

recursively sort the first part

recursively sort the second part

}

}

3. Design an experiment to determine the best "cutover" size for the combined "quicksort-plusinsertion- sort" implementation. You'll 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. You'll need to provide the sort code itself (use your code from prac 5) as well as a suitable main function for testing it (adapt the main function from prac 5).

Your experimental design should be sufficiently detailed that you could hand the task over to a tester who is not familiar with sorting algorithms or even with programming. Ideally, the tester should only need to run the program under specified conditions and record the results.

4. Run your proposed experiment and report on the findings. Your report should include the data you gather, an analysis of that data, and a clear recommendation as to the best cutover threshold.

Consider how best to present your data. You'll certainly want to tabulate the data, but you might also find it helpful to plot it as well. Because the actual times will be heavily dependent on the data size, you might find it useful to normalise the times against the "ideal" time (by dividing by n log n) before plotting them.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9527257

Have any Question?


Related Questions in Computer Engineering

Williamnbspis interested in knowingnbspwhether or not

William is interested in knowing  whether or not athletics from his team have lower satisfaction with their team on a survey than the known population average survey score of 19  and the known population survey standard ...

When is a subclass a subclasswhen programming or solving

When is a Subclass a Subclass When programming, or solving any sort of problem for that matter, abstraction plays a key role in the decision-making process. It allows you to remove irrelevant details in order to understa ...

Answer the following questions whats the synchronous

Answer the following Questions : What's the synchronous distribution ? What are the guidelines for menu layout or list them?

Advertisements suggest that a new window design can save

Advertisements suggest that a new window design can save $400 per year in energy cost over its 30-year life. At an initial cost of $8,000 and zero salvage value, using IRR, is this window a good investment? MARR is 8%.

Answer the following question a suppose alice shares a

Answer the following Question : a. Suppose Alice shares a secret block cipher key, K_AB with Bob, and a different secret block cipher key, K_AC with Charlie. Describe a method for Alice to encrypt an m-block message such ...

Design a combinational circuit with three inputs a b and c

Design a combinational circuit with three inputs: A, B, and C, D and the output W. The output should be 1 only when the values of A, B interpreted as an unsigned integer (AB) is equal to the values of C, D interpreted as ...

Sometimes during the manufacturing of an integrated circuit

Sometimes during the manufacturing of an integrated circuit, wires-including control signal wires-are accidentally connected to +V or GND, resulting in a control signal that is stuck-at-1 (when connected to +V) or stuck- ...

Question suppose an instruction can be carried out in 3

Question : Suppose an instruction can be carried out in 3 stages, the stages taking 3 ns, 7 ns, and 10 ns, respectively. (a) What is the maximum execution rate without pipelining? (b) What speedup is possible with pipeli ...

Question suppose you are planning a party for 10 friends

Question : Suppose you are planning a party for 10 friends. You decide to make sandwiches to serve at the party, no more than one sandwich per person. Seven of your friends say they want turkey. Five say they want roast ...

Question project assignment is to have you do more research

Question: Project assignment is to have you do more research on the physical security topic. In theory, everything may look straight forward, however, in real life it might not be like that. In this project you will need ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As