MHB This is the algorithm of Quicksort

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion centers on the Quicksort algorithm, detailing its structure and the necessity of the swap operation after partitioning. The swap command, swap(A[q],A[r]), is essential for placing the pivot in its correct position after partitioning. When q equals p+1, the cost of Partition is O(n), leading to recursive calls that require further analysis to determine overall cost. The worst-case cost formula T(n)=max_{0 ≤ q ≤ n-1} (T(q)+T(n-q-1)) + Θ(n) reflects the maximum time complexity when the pivot selection results in unbalanced partitions. Understanding these elements is crucial for analyzing Quicksort's efficiency and performance in different scenarios.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hi! (Nerd)

This is the algorithm of [m] Quicksort [/m], according to my notes:

Code:
Quicksort(A,p,r)
   if (p>=r) return;
   q=Partition(A,p,r);
   swap(A[q],A[r]);
   Quicksort(A,p,q-1);
   Quicksort(A,q+1,r)

Code:
Partition(A,p,r)
  x=A[r];
  i=p-1;
  for (j=p; j<r; j++){
       if (A[j]<=x){
          i=i+1;
          swap(A[i],A[j]);
       }
  }
  swap(A[i+1],A[r]);
  return i+1;

Why is this command: [m] swap(A[q],A[r]); [/m] needed at the algorithm of [m]Quicksort[/m]?
Don't we swap these values in [m] Partition [/m] ? (Thinking)
 
Technology news on Phys.org
Also, which is the cost when $q=p+1$ and which when $q=\lfloor \frac{p+r}{2} \rfloor$ ?

When $q=p+1$, we will have the cost of [m]Partition[/m] that is $O(n)$ and we will have to call the functions [m]Quicksort(A,p,p)[/m] and [m]Quicksort(A,p+,r)[/m], right? How can we find then the cost? (Thinking)Could you also explain me why this: $T(n)=\max_{0 \leq q \leq n-1} (T(q)+T(n-q-1))+\Theta(n)$ is the cost of the worst case? (Worried)
 
Last edited:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
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...
Back
Top