Cookie Preferences

We use cookies to enhance your experience. Choose your preference for cookie usage.

Essential cookies are required for basic functionality. Additional cookies help us improve our service and provide analytics.

View third-party services
  • Google Analytics: Website traffic analysis and conversion tracking
  • RudderStack: Analysis of user interactions with the website
  • Microsoft Clarity: User behavior analysis & session recordings
  • Facebook Pixel: Marketing analysis of user activity
Regression Group

Math, sorting, matching, table

Theory

Math

Report a typo

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 nn? 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 nn. For example, your output may look like this: 3 * n + 13.

Answer is:

4 * n^2 + 9 * n -10

Enter a math formula
___

Create a free account to access the full topic