Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Radix Sort-Algorithm Fundamentals-Assignment Solution, Exercises of Algorithms and Programming

Solved assignment for Algorithm Fundamentals. Submitted to Prof. Jeevanlata Khatri at Avinashilingam University. It includes: Radix, Sort, Intermediate, Stable, Array, Digits, Induction, Hypothesis, Elements

Typology: Exercises

2011/2012

Uploaded on 08/01/2012

shamabhat_84
shamabhat_84 ๐Ÿ‡ฎ๐Ÿ‡ณ

80 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 502 Fundamental of Algorithms
Assignment # 02
Spring 2012 Total Marks = 20
Deadline
Your๎˜ƒassignment๎˜ƒmust๎˜ƒbe๎˜ƒuploaded๎˜ƒ/๎˜ƒsubmitted๎˜ƒbefore๎˜ƒor๎˜ƒon๎˜ƒMay 02, 2012
Upload Instructions
Please๎˜ƒview๎˜ƒthe๎˜ƒassignment๎˜ƒsubmission๎˜ƒprocess๎˜ƒdocument๎˜ƒprovided๎˜ƒto๎˜ƒyou๎˜ƒby๎˜ƒthe๎˜ƒ
Virtual๎˜ƒUniversity.๎˜ƒ
๎˜ƒ
Rules for Marking
Please๎˜ƒnote๎˜ƒthat๎˜ƒyour๎˜ƒassignment๎˜ƒwill๎˜ƒnot๎˜ƒbe๎˜ƒgraded๎˜ƒif:๎˜ƒ
โ€ข It๎˜ƒis๎˜ƒsubmitted๎˜ƒafter๎˜ƒdue๎˜ƒdate๎˜ƒ
โ€ข The๎˜ƒfile๎˜ƒyou๎˜ƒuploaded๎˜ƒdoes๎˜ƒnot๎˜ƒopen๎˜ƒ
โ€ข The๎˜ƒfile๎˜ƒyou๎˜ƒuploaded๎˜ƒis๎˜ƒcopied๎˜ƒfrom๎˜ƒsomeone๎˜ƒelse๎˜ƒor๎˜ƒfrom๎˜ƒinternet๎˜ƒ
โ€ข It๎˜ƒis๎˜ƒin๎˜ƒsome๎˜ƒformat๎˜ƒother๎˜ƒthan๎˜ƒ.doc
Note: Material that is an exact copy from handouts or internet would be graded
Zero marks. Your solution should consist of the material found through
different sources and written in your own words.
Assignment Statements:
Question:
Use induction to prove that radix sort works. Where does your
proof need the assumption that the intermediate sort is stable?
Solution:
Basis: If d = 1, thereโ€™s only one digit, so sorting on that digit sorts
the array.
Inductive step: Assuming that radix sort works for d โˆ’ 1 digits, we
will show that it works for d digits.
Radix sort sorts separately on each digit, starting from digit 1.
Thus, radix sort of d digits, which sorts on digits 1, . . . , d is
equivalent to radix sort of the low-order d โˆ’ 1 digits followed by a
sort on digit d. By our induction hypothesis, the sort of the low-
order d โˆ’1 digits works, so just before the sort on digit d, the
elements are in order according to their low-order d โˆ’ 1 digits.
docsity.com
pf2

Partial preview of the text

Download Radix Sort-Algorithm Fundamentals-Assignment Solution and more Exercises Algorithms and Programming in PDF only on Docsity!

CS 502 Fundamental of Algorithms

Assignment # 02

Spring 2012

Total Marks = 20

Deadline

Your assignment must be uploaded / submitted before or on May 02, 2012

Upload Instructions

Please view the assignment submission process document provided to you by the Virtual University.

Rules for Marking

Please note that your assignment will not be graded if:

  • It is submitted after due date
  • The file you uploaded does not open
  • The file you uploaded is copied from someone else or from internet
  • It is in some format other than .doc

Note: Material that is an exact copy from handouts or internet would be graded Zero marks. Your solution should consist of the material found through different sources and written in your own words.

Assignment Statements:

Question:

Use induction to prove that radix sort works. Where does your proof need the assumption that the intermediate sort is stable?

Solution:

Basis: If d = 1, thereโ€™s only one digit, so sorting on that digit sorts the array. Inductive step: Assuming that radix sort works for d (^) โˆ’ 1 digits, we will show that it works for d digits.

Radix sort sorts separately on each digit, starting from digit 1. Thus, radix sort of d digits, which sorts on digits 1 ,... , d is equivalent to radix sort of the low-order d (^) โˆ’ 1 digits followed by a sort on digit d****. By our induction hypothesis, the sort of the low- order d (^) โˆ’ 1 digits works, so just before the sort on digit d , the elements are in order according to their low-order d (^) โˆ’ 1 digits.

docsity.com

The sort on digit d will order the elements by their d th^ digit. Consider two elements, a and b , with d th^ digits ad and b (^) d respectively.

  • If ad < bd , the sort will put a before b , which is correct, since a < b regardless of the low-order digits.
  • If ad > bd , the sort will put a after b , which is correct, since a > b regardless of the low-order digits.
  • If ad = bd , the sort will leave a and b in the same order they were in, because it is stable. But that order is already correct, since the correct order of a and b is determined by the low-order d (^) โˆ’ 1 digits when their d th digits are equal, and the elements are already sorted by their low-order d (^) โˆ’ 1 digits. If the intermediate sort were not stable, it might rearrange elements whose d th^ digits were equal-elements that were in the right order after the sort on their lower-order digits.

docsity.com