Give a trace for MSD string sort for the keys no is th ti fo
Give a trace for MSD string sort for the keys
no is th ti fo al go pe to co to th ai of th pa
Solution
for sorting strings that are not of same length we use MSD sort that is most significant difit first sort .
In this we consider the characters in left to right order. firstly we sort the string according to their first letters when they are sorted then we sort for each letter because in each first letter there may be sorting for next subsequent characters.
In this question we have
no,is th,ti,fo,al,go,pe,to,co,to,th,ai,of,th,pa
Here all the keys are of length 2 so we first sort them with first letters so the string keys with character a will come on top then b thn c and so on lets sort them.
al,ai,co,fo,go,is,no,of,pe,pa,th,ti,to,th,th,
now we will sort for the next sub sequent letters in each array of first letters its like dictionary sorting.
ai,al,co,fo,go,is,no,of,pa,pe,th,th,th,ti,to
this is the final sorted list .
