Is there also an other way to prove the sentence?

  • Context: MHB 
  • Thread starter Thread starter evinda
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on proving the correctness of the insertion sort algorithm using loop invariants. The user presents the algorithm and a proof from their textbook, which includes initial control, preservation control, and verification of the result. They inquire about alternative proof methods beyond induction, expressing a desire for different approaches to validate the sorting process. The conversation emphasizes the importance of understanding loop invariants in algorithm analysis.

PREREQUISITES
  • Understanding of insertion sort algorithm
  • Familiarity with loop invariants in algorithm analysis
  • Basic knowledge of mathematical induction
  • Experience with algorithm correctness proofs
NEXT STEPS
  • Research alternative proof techniques for algorithm correctness
  • Explore the concept of loop invariants in depth
  • Learn about other sorting algorithms and their proof methods
  • Study formal verification methods for algorithms
USEFUL FOR

Computer science students, algorithm researchers, and software developers interested in understanding and proving algorithm correctness.

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)
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
3K
Replies
31
Views
3K
Replies
9
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
Replies
1
Views
1K