Linda Creates Algorithm Takes Input Sequence S Produces Output Sequence T Sorting N Elemen Q37128348

Linda creates an algorithm that takes an input sequence S andproduces an output sequence T that is a sorting of the n elementsof S.
a) In Java, give an algorithm, isSorted, for testing in O(n) timeif T is sorted.
b) Explain why the algorithm isSorted is not sufficient to prove aparticular output T of Linda’s algorithm is a sorting of S.
c) Describe what additional information Linda’s algorithm couldoutput so that her algorithm’s correctness could be established onany given S and T in O(n) time.


Answer


a) The following Java code is a simple test to check whether astring array sort function works

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.