Many operations can be performed faster on sorted than on unsorted data. For whi
ID: 3547104 • Letter: M
Question
Many operations can be performed faster on sorted than on unsorted data. For which of the following operations is this the case?
a. Checking wheter one word is an anagram of another word, eg.,plum and lump
b. find an item with a minimum value
c. computing an average of values
d. finding the middle value (the median)
e. finding the value that appears most frequently in the data
Give a one or two sentence explanation for why you say each operation would benefit from using sorted vs. unsorted data.
Explanation / Answer
a) This option is very broad. It doesnt specify whether it is stored in a linked list or an array.
Although, sorted data might provide a slight advantage.
b) In this case, having a sorted data is huge advantage. As we are looking for a minimum value, sorted data will provide the value either being the first or the last depending on the sorted order.
c) In computing averages, sorted data will not provide any advantage. As we anyhow have to add all the values not just pick some among the list.
d) Definitely, having a sorted data will help in finding the middle value.
In order to get the middle value after sorted data, you just have to get the value stored in the middle index in case of odd number of values. And in case of even you just need to take the average of thevalues stored in middle two indexes.
e) Yes, sorted data will help in cases where you have large set of data. As identical values will grouped together so getting the longest run of the values will be easier with the sorted data.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.