Question: Prove by induction that WEIRDSORT correctly sorts any input array (of size a power of two). ( Hint : Formulate a claim for what STRAIGHTEN

 Prove by induction that WEIRDSORT correctly sorts any input array (of

Prove by induction that WEIRDSORT correctly sorts any input array (of size a power of two).

(Hint: Formulate a claim for what STRAIGHTEN is supposed to accomplish, and prove it.)

Assume that n is a power of two. Consider the following sorting algorithm: STRAIGHTEN(A[1 .. T) 1: if n-2 then 2 if A2A1 then 3: 4: end if 5: else swap A A2] WEIRDSORT(A[1..n]) 1: if n > 1 then 2 WEIRDSORT(A[1.. 3: WEIRDSORT(A+1.. n]) for i 1 to ! do swap A[i+41+ A [i+91 7: 8 end for 9 STRAIGHTEN (A[1.. 7 10 STRAIGHTEN (A5+1.. n) STRAIGHTEN(A1.. n) 5: end if AIGHTEN (AB+1 .. T]) 12: end ilf Assume that n is a power of two. Consider the following sorting algorithm: STRAIGHTEN(A[1 .. T) 1: if n-2 then 2 if A2A1 then 3: 4: end if 5: else swap A A2] WEIRDSORT(A[1..n]) 1: if n > 1 then 2 WEIRDSORT(A[1.. 3: WEIRDSORT(A+1.. n]) for i 1 to ! do swap A[i+41+ A [i+91 7: 8 end for 9 STRAIGHTEN (A[1.. 7 10 STRAIGHTEN (A5+1.. n) STRAIGHTEN(A1.. n) 5: end if AIGHTEN (AB+1 .. T]) 12: end ilf

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!