MHB Prove Correctness of Quicksort Algorithm Partition Function

  • Thread starter Thread starter mathmari
  • Start date Start date
AI Thread Summary
To prove the correctness of the Partition function in the Quicksort algorithm, it is essential to articulate a precise statement that holds true after the algorithm's execution. This involves demonstrating that the elements in the array are correctly partitioned around a chosen pivot, ensuring that all elements less than the pivot are on one side and all elements greater than or equal to it are on the other. The discussion references a version of the partition algorithm from Wikipedia and suggests that, with minor adjustments, the presented algorithm remains one of the most efficient known for partitioning. The focus is on understanding the correctness proof rather than the algorithm's efficiency, emphasizing the need for a clear and verifiable statement regarding the algorithm's outcome.
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)
 
Technology 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:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top