Suppose findmin is an algorithm that finds the minimum of a set and has a worst-case time complexity of Oxn). The function prepend takes a set and adds a new element in the first position. The given algorithm sorts a list in ascending order.

Respuesta :

The worst case complexity for the algorithm is O(n²)

In the worst case, every time we call the function findmin(list)

where list of length n, it will take  O(n)  operations.

For simplicity we can assume it will take n operations.

Since in each call , list decreases in one element  until it is finally empty.

the number of operations in the while loop is:

n(n-1)+(n-2)+....2+1 = n(n+1)/2= (n²+n)/2

Therefore the worst case complexity for the algorithm is O(n²).

Thus, time complexity is the number of activities a calculation performs to get done with its responsibility (taking into account that every activity requires some investment). The calculation that plays out the undertaking in the most modest number of activities is viewed as the most effective one regarding the time complexity.

To learn more about time complexities,

https://brainly.com/question/28014440

#SPJ4

Q&A Education