Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a proof for an algorithm [closed]

I am trying to compare 2 algorithms. I thought I may try and write a proof for them. (My math sucks, so hence the question.)

Normally in our math lesson last year we would be given a question like <can't use symbols in here so left them out>.

Prove: (2r + 3) = n (n + 4)

Then I would do the needed 4 stages and get the answer at the end.

Where I am stuck is proving prims and Kruskals - how can I get these algorithms in to a form like the mathmatical one above, so I can proceed to prove?

Note: I am not asking people to answer it for me - just help me get it in to a form where I can have a go myself.

like image 513
sonny Avatar asked Dec 23 '09 10:12

sonny


People also ask

How do you write a proof in algorithm?

The only way to prove the correctness of an algorithm over all possible inputs is by reasoning formally or mathematically about it. One form of reasoning is a "proof by induction", a technique that's also used by mathematicians to prove properties of numerical sequences.

How do you prove an algorithm is terminated?

Termination proof A simple, general method for constructing termination proofs involves associating a measure with each step of an algorithm. The measure is taken from the domain of a well-founded relation, such as from the ordinal numbers.

How can you prove the correctness of an algorithm using induction?

The proof consists of three steps: first prove that insert is correct, then prove that isort' is correct, and finally prove that isort is correct. Each step relies on the result from the previous step. The first two steps require proofs by induction (because the functions in question are recursive).

What is algorithm verification?

A verification algorithm is a two-argument algorithm A, where one argument is an ordinary input string x, and the other argument is a binary string y called a certificate. Algorithm A verifies x if there exists a y such that A(x,y) = 1.


1 Answers

To prove the correctness of an algorithm, you typically have to show (a) that it terminates and (b) that its output satisfies the specification of what you're trying to do. These two proofs will be rather different from the algebraic proofs you mention in your question. The key concept you need is mathematical induction. (It's recursion for proofs.)

Let's take quicksort as an example.

To prove that quicksort always terminates, you would first show that it terminates for input of length 1. (This is trivially true.) Then show that if it terminates for input of length up to n, then it will terminate for input of length n+1. Thanks to induction, this is sufficient to prove that the algorithm terminates for all input.

To prove that quicksort is correct, you must convert the specification of comparison sorting to precise mathematical language. We want the output to be a permutation of the input such that if ij then aiaj. Proving that the output of quicksort is a permutation of the input is easy, since it starts with the input and just swaps elements. Proving the second property is a little trickier, but again you can use induction.

like image 146
Jason Orendorff Avatar answered Sep 20 '22 04:09

Jason Orendorff