Question: In Lecture 6, we sketched the radix sort algorithm for sorting an array of n d-digit integers, with each digit in base k, in linear

In Lecture 6, we sketched the radix sort algorithm for sorting an array of n d-digit integers, with each digit in base k, in linear time (d(n + k)). The basic algorithm is as follows:

for j=1..d do sort the input stably by each elements jth least-significant digit

The sort we used in each pass through the loop was Counting Sort, but any stable sort will work (albeit perhaps with different overall complexity). We tried this algorithm and saw that it worked on an example. Your job is to prove inductively that this algorithm works in general. The class notes suggest proving the following loop invariant: after j passes through the loop, the input is sorted according to the integers formed by each elements j least-significant digits.

18. State and prove a suitable base case for the proof.

19. Now state and prove an inductive case for the proof. You may assume that the per-digit sort used in each iteration is (1) correct and (2) stable.

20. Why does the invariant imply that the radix sort as a whole is correct?

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!