Many operations are faster on sorted data than on unsorted data. For each of the
ID: 3761235 • Letter: M
Question
Many operations are faster on sorted data than on unsorted data. For each of the following operations, state whether it could be performed faster if the data values were sorted (do not take the cost of the sorting into account). Justify your answer. Hint: Notice I did specify a particular data structure.
a. Checking if a data set contains two words that are anagrams of each other (e.g., plum and lump).
b. Does there exist an item in the list that is at least as large as some other value?
c. Computing the average of a data set.
d. Finding the mode of a data set.
Explanation / Answer
a. it wont perform faster because you have to check each and every word for the anagram as there is no sorting among the words which are anagrams this operation wont be benefited from sorting.
b. Yes, because the value we are looking for will be the next in the list to the element in consideration.
c. No, we have to traverse full list for finding the average.
d. No, again we have to traverse full list for maintaining the mode within the list.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.