Question

In: Computer Science

1. Prove by induction on the column being sorted that RADIX-SORT correctly sorts its input. The...

1. Prove by induction on the column being sorted that RADIX-SORT correctly sorts its input. The Induction should include the following steps: Loop Invariant, Initialization, Maintenance, and Termination.

Solutions

Expert Solution

ANS:-

Radix sort is a fast algorithm which can be used
to sort k-digit integers base r (the radix).
radixSort(L). Input: linked list L.
Action: the cells on L are rearranged so that the
list is sorted.
The digits of the integer x are numbered as
x= dk-1, dk-2, ... , d2, d1, d0

*PSEUDO CODE*

for (i=0; i < k; i++)
for (j=0; j < r; j++)
Set Lj
to be an empty list.
while (L is not empty) do
Take the first cell off the front of L.
Let d be digit i of the key value x stored
in this cell. Add this cell to the end of
the list Ld
.
endwhile
Set L to be an empty list.
for (j=0; j < r; j++) Append Lj
to the end of L.

PROOF:-( BY INDUCTION)

LOOP INVARIANT:-

At the beginning of the for loop, the array is sorted on the last i-1 digits.

INITIALIZATION:-

The array is trivially sorted on the last 0 digits.

MAINTENANCE:-

Let's assum that the array is sorted on the last i-1 digits.After we sort on the ith digit, the array will be sorted on the last i digits.It is obvious that elements with different digit in the ith position are ordered accordingly; in the case of the same ith digit,we still get a corrct order, because we're using a stable sort and the elements were already sorted on the last i-1 digits.

TERMINATION:-

The loop terminates when i=d+1. Since the invariant holds, we have the numbers sorted on d digits.


Related Solutions

Prove by argument that heapsort and merge sort are asymptotically optimal comparison sorts.
Prove by argument that heapsort and merge sort are asymptotically optimal comparison sorts.
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers by repeatedly calling a “swap” subroutine. The original unsorted list of integers should be received from the keyboard input. Your program should first prompt the user “Please input an integer for the number of elements:”. After the user enters a number and return, your program outputs message “Now input each element and then a return:”. For example, if the user enters 5 as the...
4. Suppose you need to sort input data that is almost-sorted, meaning large stretches of the...
4. Suppose you need to sort input data that is almost-sorted, meaning large stretches of the data are already in increasing order with occasional out-of-order elements. Argue that INSERTION-SORT would tend to be more time efficient than QUICKSORT in this situation. Describe a scenario (other than sorting checks by check number or processing date) in which one might need to sort almost-sorted data.
The insertion sort algorithm updates its sorted array as each new data value is entered. It...
The insertion sort algorithm updates its sorted array as each new data value is entered. It is an in-place algorithm, in that the sorted array at each step writes over the array from the previous step. • Let us start with sorting in descending order (largest to smallest). The ascending order case follows as a simple modification to the descending case. • Assume that we have thus far read N values and these are sorted in correct order (largest to...
Implement Heap Sort and Quick Sort in different programs with the following specifications: 1. The input...
Implement Heap Sort and Quick Sort in different programs with the following specifications: 1. The input to the programs should be ASCII characters 2. Your program should be able to handle upper and lower case letters both 3. The sort should be done in a descending manner 4.Note: Please use array-based representation for these sorting algorithms Please write comment n explain each step clearly as well your program should show what you are taking as input array and what your...
Ex 4. (a) Prove by induction that ∀n∈N,13+ 23+ 33+···+n3=[(n(n+ 1))/2]2 b) Prove by induction that...
Ex 4. (a) Prove by induction that ∀n∈N,13+ 23+ 33+···+n3=[(n(n+ 1))/2]2 b) Prove by induction that 2n>2n for every natural number n≥3.
Prove these scenarios by mathematical induction: (1) Prove n2 < 2n for all integers n>4 (2)...
Prove these scenarios by mathematical induction: (1) Prove n2 < 2n for all integers n>4 (2) Prove that a finite set with n elements has 2n subsets (3) Prove that every amount of postage of 12 cents or more can be formed using just 4-cent and 5-cent stamps
Prove by induction: 1 + 1/4 + 1/9 +⋯+ 1/?^2 < 2 − 1/?, for all...
Prove by induction: 1 + 1/4 + 1/9 +⋯+ 1/?^2 < 2 − 1/?, for all integers ?>1
By induction: 1. Prove that Σni=1(2i − 1) = n2 2. Prove thatΣni=1 i2 = n(n+1)(2n+1)...
By induction: 1. Prove that Σni=1(2i − 1) = n2 2. Prove thatΣni=1 i2 = n(n+1)(2n+1) / 6 .
Create a quick and merge sort algorithm that sorts 6 9 8 12 3 1 7...
Create a quick and merge sort algorithm that sorts 6 9 8 12 3 1 7 In java please.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT