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)
 
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...
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
Back
Top