Question

In: Computer Science

Show that the worst case of the Quicksort is Ω(n2)

  1. Show that the worst case of the Quicksort is Ω(n2)

Solutions

Expert Solution

Here is the algorithm of quick sort :

In the baove algorithm , partition takes O(n) time. After each partition, we divide our array into two part. First part contains element from p to q-1 (i.e. n-r-1 elements )and second part contains element from q+1 to r (i.e. r elements).

Therefore, we can write recurrence relation as :
T(n) =T(n-r-1) +T(r) +O(n) , where, n is the total no of elements in array.
n-r-1 is the no elements in one part after partition
   r is the no of elements in other part [ As 1 element will be at its correct position as which element partition is performed ]
   O(n) is the time required to perform partition

In worst case, there will be no element in one part whereas n-1 elements in the other part .
Therefore, T(n) =T(n-1) +T(0) +O(n)
   =T(n-1) +cn
= T (n-2) + c(n-1) +cn [ As T(n-1) =T(n-2) +c(n-1) ]
     = T (n-3) + c(n-2) +c(n-1) +cn [ As T(n-2) =T(n-3) +c(n-1) ]
= c(1) +c(2) +c(3) +.... + c(n-2) +c(n-1)+cn
= cn(n+1)/2
=O (n2 )

Therefore, worst case complexity of quick sort =
Hence, proved.

Here are some examples that shows time complexity of when quick sort is applied .

  


Related Solutions

Show that the worst-case and average-case time complexities for the number of assignments of records performed...
Show that the worst-case and average-case time complexities for the number of assignments of records performed by the Exchange Sort algorithm (Algorithm 1.3) are given by           W(n) = 3n(n-1)/2 ≈ n2/2 and A(n) = 3n(n-1)/4 ≈ n2/4
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the...
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the 0-1 Knapsack problem is in Ω(2n). Do this by considering the instance in which W = 2n −2 and wi = 2i−1 for 1 ≤ i ≤ n. Please answer with clear explanations!!! Excerpt From: Richard Neapolitan. “Foundations of Algorithms.”
Please state the worst case run time for the following with an example of the worst...
Please state the worst case run time for the following with an example of the worst case and explain why! 1. Dijksta's Algorithm 2. Bellman-Ford Algorithm 3.DAG Algorithm 4. Prim's Algorithm 5. Kruskal's Algorithm 6. Baruvka's algorithm
What is the best case and worst case performance for a hashtable lookup explain answer very...
What is the best case and worst case performance for a hashtable lookup explain answer very clearly and answer must be explained how hashtables work and how that relates to performance in both the cases.
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of...
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of the time, the element x to search for is not in the list and if x is in the list, it is equally likely to be in any position.
1. Show that if u is harmonic in a domain Ω, then also the derivatives of...
1. Show that if u is harmonic in a domain Ω, then also the derivatives of u of any order are harmonic in Ω. (Hint: To get the result for any order you may want to use induction).
Suppose that a bank has a total of $100 million of credit exposure, and the worst-case...
Suppose that a bank has a total of $100 million of credit exposure, and the worst-case default rate over one-year is equal to 0.031. Which of the following is true about the WCDR? Select one: a. The WCDR is a positive function of the correlation between loans. b. If loan defaults are independent of one another, then WCDR < 0.031. c. According to Basel requirements the WCDR is the default rate by time T = one year that will not...
QUESTION 8 In a base-case scenario, the output is determined by assuming a. worst values that...
QUESTION 8 In a base-case scenario, the output is determined by assuming a. worst values that can be expected for the random variables of a model. b. the most likely values for the random variables of a model. c. the mean trial values for the random variables of a model. d. best values that can be expected for the random variables of a model. e. None of the above 1.5 points    QUESTION 9 The points where constraints intersect on...
6. The worst case scenario in the quick sort occurs when the array is partitioned to...
6. The worst case scenario in the quick sort occurs when the array is partitioned to two equal sized subarray every time that a recursive call takes place. True False 7.Suppose that we want to sort an array of n elements, where each element is a string of at most 1000 characters. What is the time requirement for applying radix sort to sort this array? O(n2) O(1000n) O(l000logn) O(nlogn) 8.Suppose we want to sort the following array of integers using...
Show that (1 + 2 +. . .+n)2 > 12 +. . .+ n2, for n...
Show that (1 + 2 +. . .+n)2 > 12 +. . .+ n2, for n ≥ 2.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT