Question

In: Computer Science

What is the reason to choose a random pivot element in Randomized Quicksort? How can using...

What is the reason to choose a random pivot element in Randomized Quicksort? How can using randomization in this way possibly help?

Solutions

Expert Solution

Your regular quicksort algorithm can trigger a worst case scenario with a time complexity of O(n2) when the input is already sorted. Let me explain with the help of an example:
Assume the input sequence to be 1,2,3,4,5,6,7,8,9,10.
Now, if you take 1 as your pivot element you will recursively sort 2,3,4….10.
In second pass, if you take 2 as your pivot element you will recursively sort 3,4,5…10.
In third pass, if you take 3 as your pivot element you will recursively sort 4,5,6….10 and so on.
In the first pass you are looking at n-1 elements, in the second pass you are looking at n-2 elements, in third pass you are looking at n-3 elements. For an input which is already sorted, the regular quicksort takes a lot of time for the program to completely execute.
In a randomised quicksort algorithm since you are randomly selecting a pivot point, there isn’t any just one input which can trigger a worst case scenario like in the above situation. The randomness of it all ensures an expected run time of O(n log n).
In addition to this, the quicksort algorithm is vulnerable to certain security threats like the DoS attack. Using randomised quicksort will less likely expose you to vulnerabilities like these.


Related Solutions

If we change the randomized QUICKSORT algorithm so that it repeatedly randomly selects a pivot and...
If we change the randomized QUICKSORT algorithm so that it repeatedly randomly selects a pivot and runs PARTITION until it finds a good pivot, and suppose we keep track of the pivots used so far so we never use one twice for the same array, what is the worst case cost of the algorithm? Give a recurrence for this and its asymptotic solution (you can use the master method.)
. Consider QuickSort on the array A[1:n] and assume that the pivot element x (used to...
. Consider QuickSort on the array A[1:n] and assume that the pivot element x (used to split the array A[lo:hi] into two portions such that all elements in the left portion A[lo:m] are ≤x and all elements in the right portion A[m:hi] are ≥x) is the second element of the array to be split (i. e., A[lo+1]). For a specific value of n at least 13 (your choice), construct an assignment of the numbers 1...n to the n array elements...
Consider QuickSort on the array A[1:n] and assume that the pivot element x (used to split...
Consider QuickSort on the array A[1:n] and assume that the pivot element x (used to split the array A[lo:hi] into two portions such that all elements in the left portion A[lo:m] are ≤x and all elements in the right portion A[m:hi] are ≥x) is the second element of the array to be split (i. e., A[lo+1]). For a specific value of n at least 13 (your choice), construct an assignment of the numbers 1...n to the n array elements that...
What is the main reason for using covariance analysis in a randomized study?
What is the main reason for using covariance analysis in a randomized study?
implement c++ Quicksort using median of 3 as pivot. this also pass comparator as a function...
implement c++ Quicksort using median of 3 as pivot. this also pass comparator as a function param so it can sort vector in increasing or decreasing order based on the comparator passed. the test code uses std::less comparator. #ifndef QSORT_H #define QSORT_H #include #include using namespace std; template T median_of_three(T& a, T& b, T& c, TComparator comparator) { } template size_t partition(vector& vec, TComparator& comparator, size_t low, size_t high) { // TODO: implement. } template void QuickSort(vector& vec, TComparator comparator,size_t...
What type of algorithm is the Quicksort algorithm if it has random pivots?
What type of algorithm is the Quicksort algorithm if it has random pivots?
What is the advantage of using a Pivot Chart to a regular chart in exel?
What is the advantage of using a Pivot Chart to a regular chart in exel?
Can you anaylze the business strategy used by Xiaomi, within the reason that they choose that....
Can you anaylze the business strategy used by Xiaomi, within the reason that they choose that. (Subject: Business Strategy) Also provide a VRIO anaylsis framework of Xiaomi, to find its resources and capabilities whether can be sustainable competitive advantage.
Pivot Tables - Please explain how to acheive the following: Using the data below, create a...
Pivot Tables - Please explain how to acheive the following: Using the data below, create a Pivot Table that answers the question “Which salesperson sold the most in any particular month.” A manager wants to click on the Pivot Table and choose a month and have the name of that person appear with his or her amount for that month. Sales Data Salesperson May June July Aug. Sept. Oct. Albertson, Kathy $3,947.00 $557.00 $3,863.00 $1,117.00 $8,237.00 $8,690.00 Allenson, Carol $4,411.00...
5 What is the most common reason that prospects give for not buying? How can salespeople...
5 What is the most common reason that prospects give for not buying? How can salespeople deal effectively with this type of concern?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT