correctness-recursive

correctness-recursive - Introduction to the Theory of...

This preview shows pages 1–8. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to the Theory of Computation AZADEH FARZAN SPRING 2010 Wednesday, January 20, 2010 CORRECTNESS OF SIMPLE RECURSIVE PROGRAMS Wednesday, January 20, 2010 MERGE SORT Merge sort takes an array A and rearranges its elements such that A [ i ] ≤ A [ i + 1] for each i ∈ N such that 1 ≤ i < length ( A ) . Wednesday, January 20, 2010 MERGE SORT To sort an array A we proceed as follows: (1) If lenght ( A ) = 1 then we are done. (2) Otherwise, let A 1 and A 2 be two halves of A . Recursively sort A 1 and A 2 . A 1 A 2 (3) Merge the two sorted subarrays A 1 and A 2 into a single sorted array A . Wednesday, January 20, 2010 MERGE SORT SPEC Wednesday, January 20, 2010 MERGE SORT SPEC Precondition. 1 ≤ f ≤ l ≤ length ( A ) . Wednesday, January 20, 2010 MERGE SORT SPEC Postcondition. A [ f . . . l ] has the same elements as before invocation, in sorted order; and all other elements of A are unchanged....
View Full Document

This note was uploaded on 04/11/2010 for the course CSC CSC236 taught by Professor Farzanazadeh during the Spring '10 term at University of Toronto.

Page1 / 24

correctness-recursive - Introduction to the Theory of...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online