Question

In: Computer Science

Show in a formal mathematical proof, theoretical analysis, substitution method, an even split of an array...

Show in a formal mathematical proof, theoretical analysis, substitution method, an even split of an array into two subarrays which answers in the best performance of quicksort algorithm "appraised with respect to the running time". coding or empirical investigation are not needed.

Solutions

Expert Solution

Quicksort is another sorting algorithm which uses Divide and Conquer for its implementation. Quicksort is also the practical choice of algorithm for sorting because of its good performance in the average case which is Θ(nlgn).

Partition in Quicksort

The first step of doing a partition is choosing a pivot. We are going to always select the last element of the array as the pivot in our algorithm and focus mainly on the concepts behind the Quicksort. However, there can be different ways of choosing the pivot like the median of the elements, the first element of the array, random element, etc.

After choosing the pivot, our next task is to place all the elements smaller than the pivot on one side and all the elements larger than the pivot on another side. We will do this by iterating over the array and on finding an element larger than the pivot, doing nothing. This will start making a cluster of elements larger than the pivot.

Analysis of Quicksort

We know that Quicksort takes Θ(n2) time in the worst case and Θ(nlgn)

in the best case.   Now, the total running time of the QUICKSORT function is going to be the summation of the time taken by the PARTITION(A, start, end) and two recursive calls to itself. The comparison (if start < end) is going to take a constant amount of time and thus, we are ignoring it.

the PARTITION function is a linear (i.e., Θ(n)

) one because there is just one loop which is iterating over the entire array (of size n) and all the other statements are constant time taking processes.

Let's take a case when the partition is always balanced i.e., every time, each of the two halves separated by the pivot has no more than n2

elements. It means that one of the halves has ⌊n2⌋ and another has ⌈n2⌉−1 elements. For example, if n is 5, then one half has ⌊52⌋=2 elements and another has ⌈52⌉−1=2

elements and thus, a total of 2+2+1(pivot) = 5 elements.

In that case, QUICKSORT(A, start, q-1) and QUICKSORT(A, q+1, end) will take T(n2)

each and the PARTITION function is going to take Θ(n) time.

Now, let's take the case when the partition is completely unbalanced every time i.e., each time, one half is of the size n−1 and other of size 0

.

In this case, the total running time would be:

T(n)=T(n−1)+T(0)+Θ(n)

=>T(n)=T(n−1)+Θ(n)

We can solve this recurrence equation by iteration method i.e., putting replacing T(n−1)

with T(n−2)+Θ(n) and again T(n−2) with T(n−2)+Θ(n)

and so on.

T(n)=T(n−1)+Θ(n)

Replacing T(n−1) with (T(n−2)+Θ(n)), =>T(n)=T(n−2)+Θ(n)+Θ(n) Replacing T(n−2) with (T(n−3)+Θ(n)), =>T(n)=T(n−3)+Θ(n)+Θ(n)+Θ(n) Similarly, T(n)=T(n−i)+i∗Θ(n)

Thus, in the base case, when there will be an only single element, the running time will become T(n)=T(0)+n∗Θ(n)

which is equal to Θ(n2)

So, we have seen that Quicksort takes Θ(nlgn)

time in the balanced partition and Θ(n2) time in the unbalanced one.

The choice of a pivot is most critical:
The wrong choice may lead to the worst-case quadratic time complexity.

A good choice equalises both sublists in size and leads to
linearithmic (\n log n") time complexity.

However, quicksort is fast on the \randomly scattered" pivots.


Related Solutions

Show in a formal mathematical proof, theoretical analysis, an even split of an array into two...
Show in a formal mathematical proof, theoretical analysis, an even split of an array into two subarrays which answers in the best performance of quicksort algorithm "appraised with respect to the running time". coding or empirical investigation are not needed.
The split method in the String class returns an array of strings consisting of the substrings...
The split method in the String class returns an array of strings consisting of the substrings split by the delimiters. However, the delimiters are not returned. Implement the following new method that returns an array of strings consisting of the substrings split by the matching delimiters, including the matching delimiters. public static String[] split(String s, String regex) For example, split("ab#12#453", "#") returns ab, #, 12, #, 453 in an array of String, and split("a?b?gf#e", "[?#]") returns a, ?, b, ?,...
In the proof of bolzano-weierstrass theorem in R^n on page 56 of "Mathematical Analysis" by Apostol,...
In the proof of bolzano-weierstrass theorem in R^n on page 56 of "Mathematical Analysis" by Apostol, should the inequality be a/2^(m-2) < r/sqrt(n) or something related to n? a/2^(m-2) < r/2 seems not enough
Create a method evenOdd() that sorts an array into even numbers on one side and the...
Create a method evenOdd() that sorts an array into even numbers on one side and the odd numbers on the other side public class ourArray { int[] Ar; int size; public int getSize() {    return size; } public ourArray() {    Ar = new int[100];    size = 0; } public void add(int e) {    Ar[size]= e;    size++; } public int remove() {    //save the last item           int save = Ar[size -1];   ...
PROOF; COMPLEX ANALYSIS Show that the sequence {z_n} = {z_1, z_2, ...} is said to converge...
PROOF; COMPLEX ANALYSIS Show that the sequence {z_n} = {z_1, z_2, ...} is said to converge to the complex number w if and only if the sequence of real and imaginary parts of z_n converge to the real and imaginary parts of w, repectively. PLEASE DETAILED PROOF IS REQUIRED. THANKS
Describe theoretical and regional flood frequency analysis method for computation of flood hazard.
Describe theoretical and regional flood frequency analysis method for computation of flood hazard.
Using formal English and the expository method of Process Analysis produce a complete sentence outline (as...
Using formal English and the expository method of Process Analysis produce a complete sentence outline (as a pair) TWO body paragraphs (per member) and a conclusion based on the following: Access to adequate healthcare is the right of every Caribbean citizen- ·       Discuss the steps taken in Barbados to ensure that healthcare can be accessed by all of its citizens.
CVP and Break-Even Goal: Create an Excel spreadsheet to perform CVP analysis and show the relationship...
CVP and Break-Even Goal: Create an Excel spreadsheet to perform CVP analysis and show the relationship between price, costs, and break-even points in terms of units and dollars. Use the results to answer questions about your findings. Scenario: Phonetronix is a small manufacturer of telephone and communications devices. Recently, company management decided to investigate the profitability of cellular phone production. They have three different proposals to evaluate. Under all the proposals, the fixed costs for the new phone would be...
Concept for Analysis 8-10 PLEASE SHOW WORK Concord Company is considering changing its inventory valuation method...
Concept for Analysis 8-10 PLEASE SHOW WORK Concord Company is considering changing its inventory valuation method from FIFO to LIFO because of the potential tax savings. However, management wishes to consider all of the effects on the company, including its reported performance, before making the final decision. The inventory account, currently valued on the FIFO basis, consists of 1,000,000 units at $8 per unit on January 1, 2017. There are 1,000,000 shares of common stock outstanding as of January 1,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT