HW4 Ans - 1. When doing LSD Radix Sort on numbers, a trick...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1. When doing LSD Radix Sort on numbers, a trick to making the number of digits be equal is to assign leading zeroes to the smaller numbers. For example, the data set {3, 50, 123, 66, 9} becomes {003, 050, 123, 066, 009}. Can you do the same thing with LSD Radix on lowercase English words? Why or why not? If not, show a counter-example and provide an alternative. Use # to be a symbol that is less than all lowercase letters (e.g. {a, ab} becomes {#a, ab} if we use leading #). No, this method would not work for strings. Consider the data set {#z, ab}. In LSD’s first pass, it will have ab before #z. However, in the second (and last) pass, it will have #z and ab, which is illegal since z occurs after ab in alphabetical order. An alternative solution that works is using trailing #’s instead. For example, {z#, ab} will sort correctly. Note that this is very similar to how you handled strings for MSD in the homework. Bucket[0] contained strings that didn’t have a character at a certain index. Simply insert a # in that index.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

HW4 Ans - 1. When doing LSD Radix Sort on numbers, a trick...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online