Question

In: Computer Science

Design a version of QuickSort that uses a threshold. Do empirical testing to determine a good threshold value.

The following submission rules apply:

·    For those questions requiring programs, the solutions must be implemented using JavaScript or Java.

o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices.

o Solutions must be provided in plain text so that formatting is not lost.

·    All answers must be provided in this document.

·    Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them.

Design a version of QuickSort that uses a threshold. Do empirical testing to determine a good threshold value.

Solutions

Expert Solution

Quicksort is one of the fastest sorting algorithms for sorting data.

The implementation of a simple sequential Quicksort algorithm follows that we choose for our needs is: 1.Select a pivot element.

2. Iterate through the sorting area, place all numbers smaller then the pivot element to left, and place all other numbers to right. Done by swapping elements.

3. The pivot element is now in its sorted position and continue with the divide-and conquer strategy, applying the same algorithm on the part of left and right of pivot.

By using a threshold, sequential sorting alogorithms saves the computational cost.

With parallel algorithm, we have to remember that the cost of creating, monitoring and managing of the parallel tasks is added to the total computational cost. Assume that the average case of quicksort with computational time O(nlogn).

When using parallel computing, the computational cost consists of these values:

1. pick the pivot – O(1)

2. move the elements to the left and right side of pivot - O(n)

3. create new tasks to sort the left and right part of the pivot - O(1)

For each leaf node of the tree, perform a sequential quicksort, the size of the leaf node depends upon the threshold T.

Using Threshold quicksort can be implemented in efficient way as below:

  1. void thresholdquicksort(int * var, int p, int q)
  2. {
  3.    int r;
  4.    while(p < q)
  5.    {
  6.       r = partition(var, p, r);
  7.       if(r - l < q - r) //recurse into the smaller half
  8.       {
  9.          quicksort(var, p, r - 1);
  10.          l = r + 1;
  11.       } else
  12.       {
  13.          quicksort(var, r + 1, q);
  14.          q = r - 1;
  15.       }
  16.    }
  17. }

Related Solutions

This assignment uses hypothesis testing to determine if there is a significant difference between the means...
This assignment uses hypothesis testing to determine if there is a significant difference between the means of three or more groups. Find solutions to the following problems. Be sure to include a statement about significance and complete a Tukey's HSD when necessary. Subjects were interviewed about their smoking habits in cigarettes per day and were tested for their aerobic capacity. Taking cigarettes per day as the explanatory (independent) variable and aerobic capacity as the response (dependent) variable, find the correlation...
Subject: Software, Architecture Design and Testing You are to determine the user requirements for a web...
Subject: Software, Architecture Design and Testing You are to determine the user requirements for a web phone-mail product. The primary purpose of this product is to give phone-mail users (e.g., faculty and staff) the ability to access the functionality of the phone-mail system from a web page. In general, the product should enable users of the phone-mail system to do their usual phone-mail activities via a web page. Evaluate these requirements. Do your requirements satisfy the eight criteria: Understandable, Verifiable,...
Design a device that uses an electrochemical cell to determine the amount of Cu2+ in a...
Design a device that uses an electrochemical cell to determine the amount of Cu2+ in a sample of water. Describe, in detail, the construction and the theory of operation of your device. If you areable to measure voltage with one-millivolt accuracy, what will the uncertainty in your measured concentration?
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any...
1.Describe a design pattern that incents good security behavior. 2.Design a hash function that uses any desired date as the salt. Demonstrate operation of the function, including input values. Describe benefits and shortcomings of the hash function.
" it is always good for a country to have a high currency value !" do...
" it is always good for a country to have a high currency value !" do you agree with this starement ? discuss with relevant examples .
Do all hypothesis testing steps and find the correlation coefficient for the following data to determine...
Do all hypothesis testing steps and find the correlation coefficient for the following data to determine if there is a significant correlation between the results of IQ test and Test A scores. (A higher score on either tests = a “better” score”) A.Also make a scatterplot (by hand) for this data. (IQ is X and Test Score is Y, also begin at 90 for X and 30 for Y) B.Calculate the regression equation for predicting scores on the Y’(Reading test)...
How do you determine the “value” of a product or service?
How do you determine the “value” of a product or service?
How do financial managers determine the value of a business?
How do financial managers determine the value of a business?
Determine the p-value for testing: H0: µ = 15 Ha: µ > 15 when a random...
Determine the p-value for testing: H0: µ = 15 Ha: µ > 15 when a random sample of size 18 was taken from a normal population whose standard deviation is unknown and the value of the test statistic equals 2.35. The 98% confidence interval for the population proportion of successes when a random sample of size 80 was taken from a very large population and the number of successes in that sample was counted to be 20.  No concluding statement is...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day...
PLEASE DO THIS IN C#Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample runs below. Sample run...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT