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 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...
I need the exact answer for: Best-case NPV: Worst-case NPV McGilla Golf has decided to sell...
I need the exact answer for: Best-case NPV: Worst-case NPV McGilla Golf has decided to sell a new line of golf clubs. The clubs will sell for $855 per set and have a variable cost of $415 per set. The company has spent $320,000 for a marketing study that determined the company will sell 70,000 sets per year for seven years. The marketing study also determined that the company will lose sales of 13,400 sets of its high-priced clubs. The...
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios....
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios. As future planning becomes more complex, these what-if analyses can increase in complexity and usefulness. Identify and discuss at least three (3) types of what-if analyses that an accountant should be able to perform to measure a firm’s performance over a period. Be sure to include the type of data that will be needed to support this analysis. Justify your response.
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios....
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios. As future planning becomes more complex, these what-if analyses can increase in complexity and usefulness. Identify and discuss at least three (3) types of what-if analyses that an accountant should be able to perform to measure a firm’s performance over a period. Be sure to include the type of data that will be needed to support this analysis. Justify your response.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT