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)
 
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 have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top