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 DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full 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.
 Spring '10
 FarzanAzadeh
 Sort

Click to edit the document details