please answer this with complete details this question is a Java question thank
ID: 3696721 • Letter: P
Question
please answer this with complete details this question is a Java question thank you.
Problem 4. It is often useful to have data already sorted to perform some operations. In the questions below you need to explain whether an operation could be performed faster if the values are sorted. If yes, explain how sorting helps performance in terms of running time. If not, clearly mention the alternative method to perform the operation along with the running time complexity 1. Finding the average of a set of integersExplanation / Answer
1. Finding the average of a set of integers. For finding the average of a set of integers, usually sorting doesn't make any difference. This is because to find the average, we should sum up all the numbers, and the sum should be divided by the total number of numbers in the array. So, whether the list is ordered or not, we obviously have to add all the numbers, and then divide it by another number. But the exception is that, if the numbers are equally spread across, then its a wise idea to have a sorted list. This is because, for sorted list, the average is like middle element, or the middle 2 elements, average.
2. Computing the mode of a set of integers. Computing the mode is counting the number that appears the maximum number of times in the list. Here, sorting the list definitely gives an added advantage, compared to that of unsorted list. This is because, to count the number of times a number appears in the list, in an unsorted list, takes more time when compared to counting the same in a sorted list.
3. Computing the median of a set of integers. The median is again the middle value on a sorted list. Therefore, the middle value can be selected only on a sorted list. Therefore, sorted list will be more advantageous compared to that of an unsorted list.
4. Checking whether an item atleast least as large as some specified value exists in the array. On a sorted list this can be done easily, or in a better efficient manner. This is because, on a sorted list, you can go with binary search, instead of going with linear search.
5. Find the maximum value: This is the easiest to be done on a sorted list. If not sorted, to find the maximum value, you have to go through all the n elements, where as if the list is sorted, obviously the last element will be of maximum value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.