MHB Worst-case running time of algorithm

AI Thread 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)
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top