Is there also an other way to prove the sentence?

  • MHB
  • Thread starter evinda
  • Start date
In summary, the conversation discusses the algorithm of insertion sort and a proof for its correctness. The proof involves using a loop invariant, which is the usual method for proving the desired action of a loop. The person asking the question wonders if there is another way to prove the correctness of the algorithm.
  • #1
evinda
Gold Member
MHB
3,836
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
  • #2
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?
 
  • #3
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)
 

FAQ: Is there also an other way to prove the sentence?

How do you prove a sentence in science?

There are several ways to prove a sentence in science, including conducting experiments, gathering evidence, and using mathematical or logical reasoning.

Can a sentence be proven beyond a reasonable doubt?

Yes, a sentence can be proven beyond a reasonable doubt in science by using multiple lines of evidence and ensuring that the results are reproducible.

Is there a difference between proof and evidence in science?

Yes, there is a difference. Proof is a conclusive piece of evidence that supports a statement or theory, while evidence is any type of information that supports or refutes a claim.

What role do peer-reviewed studies play in proving a sentence?

Peer-reviewed studies are an important part of the scientific process as they involve independent experts evaluating the validity and reliability of a study's methods and findings before it is published.

Can a sentence ever be proven wrong in science?

In science, nothing can be proven with 100% certainty. However, through rigorous testing and peer review, a sentence can be supported by a significant amount of evidence, making it highly unlikely to be proven wrong.

Back
Top