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

What is recurrence for worst case of QuickSort and what is the time complexity in Worst...
What is recurrence for worst case of QuickSort and what is the time complexity in Worst case? algorithms coures
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
Given the below code, compute the values of the best case, worst case and average case...
Given the below code, compute the values of the best case, worst case and average case knowing that the basic operation in the first loop takes 4 ns to execute and the basic operation in the second loop takes 5 ns to execute. int A[20]; for (int i=0; i < 20; i++) {           cin >> A[i]; } for (i=0; i < 20; i++) {           if (A[i] % 3 == 0)                     break; }
Question 7 Use the definition of Ω to show that 20(?^3) + 5(n^2) ∈ Ω (?^3)...
Question 7 Use the definition of Ω to show that 20(?^3) + 5(n^2) ∈ Ω (?^3) Big-O, Omega, Theta complexity of functions, Running time equations of iterative functions & recursive functions,  Substitution method & Master theorem Please answer within these topics.
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.
How many key comparisons are made by mergesort in the a. Best case? b. Worst Case?
How many key comparisons are made by mergesort in the a. Best case? b. Worst Case?
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).
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT