Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem (page limit: 3 pages) A ssume that n is a power of two. Consider the following sorting algorithm: STRAIGHTEN(A1 T) : if 2 then

image text in transcribed

Problem (page limit: 3 pages) A ssume that n is a power of two. Consider the following sorting algorithm: STRAIGHTEN(A1 T) : if 2 then ifA[2]A111 then swap A A2 3: 4: end if 5: else WEIRDSORT(A1..T 1: ifn > 1 then 3 WEIRDSORT(A s: end if WEIRDSORT(All .. 6: fori1 to T do ) STRAIGHTEN(A1..) 8 end for 9: STRAIGHTEN (A1 STRAGHTEN (14+1,n/) STRAIGHTEN (AT1 10: 12: end if . Give an example proving that WEIRDSORT would not correctly sort if we removed lines 6-8 in STRAIGHTEN. 2. Give an ex ample proving that WEIRDSORT would not correctly sort if we swapped lines 10 & 11 in STRAIGHTEN 3. Prove by induction that WEIRDSORT correctly sorts any input array (of size a power of two). (Hint: Formulate a claim for what STRAIGHTEN 1s supposed to accomplish, and prove it.) 4. Write a recurrence to count the number of comparisons made by STRAIGHTEN on an array of size . Write a recurrence to count the number of comparisons made by WEIRDSORT on an array of size . Solve these two recurrences to obtain an asymptotic expression for the number of comparisons done by STRAIGHTEN and by WEIRDSORT. No need to show your calculations

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions