8.2-3
Suppose that we were to rewrite the for loop header in line 10 of the COUNTINGSORT as
10 for j = 1 to A.length
Show that the algorithm still works properly. Is the modified algorithm stable?
The algorithm would still work because we are changing only the order in which the element are processed (they were processed in reverse order earlier). The only thing that changes is the similar value elements are not processed in the same order as the input. So the algorithm works but the algorithm is not stable because of the above reason.
No comments:
Post a Comment