MHB Worst-case running time of algorithm

Click For Summary
The discussion focuses on demonstrating that the worst-case running time of the Quicksort algorithm is O(n^2). The algorithm involves selecting a random pivot and partitioning the array into three segments: elements less than, equal to, and greater than the pivot. The worst-case scenario occurs when the pivot is consistently the smallest element, leading to an unbalanced partition. This results in a series of recursive calls that can be expressed as a sum of the form n + Θ(n) + Θ(n-1) + ... + Θ(1), which simplifies to Θ(n^2). The question raised is whether this explanation suffices or if further justification, such as using a recurrence relation, is necessary to support the claim of O(n^2) complexity.
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :o

Let the quicksort algorithm be the following:

Code:
procedure QUICKSORT(S)
         if S contains at no one element then return S
         else
            begin
               choose an element a randomly from S;
               let S1, S2 and S3 be the sequences of elements in S less than, equal to and greater than a, respectively;
               return (QUICKSORT(S1) followed by S2 followed by QUICKSORT(S3))
            end

How can I show that the worst-case running time of Quicksort is $O(n^2)$ ?? (Wondering)
 
Technology news on Phys.org
choose an element a randomly from S; let S1, S2 and S3 be the sequences
of elements in S less than, equal to
and greater than a, respectively;

The above is a description of a partitioning algorithm. It can be shown that the best partitioning algorithm has order $\Theta (n)$ where n is the number of elements of S. Suppose all elements of S are different and at each call to partition (unluckily) the pivot a is the smallest element. Then the total order of quicksort is $$n+\Theta (n)+\Theta(n-1)+\cdots +\Theta(1)=\Theta(n^2)$$
 
So, to show that the worst-case running time of Quicksort is $O(n^2)$ do we have to say just the following:

johng said:
Suppose all elements of S are different and at each call to partition (unluckily) the pivot a is the smallest element. Then the total order of quicksort is $$n+\Theta (n)+\Theta(n-1)+\cdots +\Theta(1)=\Theta(n^2)$$

?? (Wondering)

Or do we have to justify it further, for example with a recurrence relation?? (Wondering)
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
9
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 30 ·
2
Replies
30
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K