MHB Is there also an other way to prove the sentence?

  • Thread starter Thread starter evinda
  • Start date Start date
AI Thread Summary
The discussion centers on the insertion sort algorithm and the proof of its correctness regarding the sorted subsequence at each iteration. The initial control shows that for j=2, the subsequence A[1] is trivially sorted. The preservation control explains how elements are shifted to find the correct position for A[j]. The verification confirms that by the end of the loop, the entire array A[1...n] is sorted. A participant inquires about alternative proof methods beyond the standard loop invariant approach, expressing a desire for different proof techniques rather than relying solely on induction. The conversation highlights the desire for diverse proof strategies in algorithm validation.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

I am looking at the algorithm of the insertion sort:

Code:
     Input: A[1 ... n]     for j <- 2 to n
        key <- A[j]
        i <- j-1
        while (i>0 and A[i]>key)
              A[i+1] <- A[i]
              i <- i-1
        end
        A[i+1] <- key
     end

There is the following sentence:

At the beginning of each iteration "for" ,the subsequence $ A[1 \dots j-1]$ consists of the elements that are from the beginning at these positions, but sorted with the desired way.

I found the following proof in my textbook:

  • Initial control, when $j=2:$
    The sentence is true,because the subsequence $A[1]$ is sorted in a trivial way.
  • Preservation control:
    The algorithm moves the elements $ A[j-1], A[j-2], \dots $ to the right side,till the right position for $ A[j] $ is found.
  • Verification of the result:
    When the loop "for" ends, $j$ has the value $n+1$. The subsequence is now $ A[1 \dots n]$, which is now sorted.

But...could you tell me if there is also an other way to prove the sentence? (Thinking)
 
Technology news on Phys.org
evinda said:
could you tell me if there is also an other way to prove the sentence?
Using a loop invariant is the usual way of proving that a loop performs a desired action. What don't you like about it and why do you want another proof?
 
Evgeny.Makarov said:
Using a loop invariant is the usual way of proving that a loop performs a desired action. What don't you like about it and why do you want another proof?

The proof is nice,I just wanted to know of the there is an other way to prove it,rather than using indunction.. (Thinking)
 
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.
Back
Top