Prove Correctness of Quicksort Algorithm Partition Function

  • Context:
  • Thread starter Thread starter mathmari
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
mathmari
Gold Member
MHB
Messages
4,984
Reaction score
7
Hey! :o

I have to prove the correctness of the function Partition of the Quicksort algorithm.

Code:
    begin
     i<-f
     j<-l
     while i<=j do
        begin
         while A[j]>=a and j>=f do j<-j-1;
         while A[i]<a and i<=l do i<-i+1;
         if i<j then 
            begin
              interchange A[i] and A[j];
              i<-i+1;
              j<-j-1;
            end
       end
    end

What am I supposed to do?? (Wondering)

What does it mean to prove the correctness?? (Wondering)
 
Physics news on Phys.org
To prove correctness of an algorithm, you must first state precisely a statement that is true after execution of the algorithm and then prove this statement. There are many different versions of the partition algorithm. I took the following from Wikipedia. Here's a proof of that algorithm. Now you should have a go at your algorithm. BTW, with a few tweaks I believe that the algorithm you described is still the most efficient partitioning algorithm known.

2gtq3rn.png

e0h91c.png
 
Last edited: