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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started