Analysing an algorithm # Application
Given below is a sorting algorithm:
sort(arr):
for i in 1..len(arr):
elem = arr[i]
j = i - 1
while j >= 0 and arr[j] > elem:
arr[j+1] = arr[j]
j = j - 1
arr[j+1] = elem
return arr
What is the total number of operations the algorithm performs for an array of size ? What is the asymptotic time complexity of the algorithm?
As an answer to this problem, print a function that shows how many operations the algorithm performs for an array of size . For example, your output may look like this: 3 * n + 13.
Answer is:
4 * n^2 + 9 * n -10