In a program, the input of items is in a sorted array (8,7,5,4,2). New numbers are coming randomly and getting added to the array such as the number 9 got added leading to - (8,7,5,4,2,9). The new array is nearly sorted but the programme needs the array to be in descending order completely. To reduce the time complexity of the algorithm, which sorting method should be used in this case?
Answers
i'm assuming that you are talking about Python language. If yes, then here's the answer.
Brainly isnt allowing me to type here. So i'll send the attachment. If helped, then pls mark brainliest!
To Find:
Sorted array in descending order if any big number is assigned to the array.
Solution:
In python language,
Let, arr be the array that has been created by listing the numbers as [8,7,5,4,2,9].
After that, we need to use the sort method with arr list to sort the following list.
But to prevail that in descending order we need to assign a condition (reverse = True), to support the above fact making the reversing ascending order to be true.
At last, we need to print the arr for availing our desired output.
The code is as follows;
arr = [8,7,5,4,2,9]
arr.sort (reverse = True)
print (arr)
#SPJ2