itm8081
itm8081

Reputation: 3

Help with asymptotic analysis

I'm rather new to programming and have recently been introduced to the topic of asymptotic complexity. What I'm curious about is how to figure out the asymptotic complexity of a sorting method, given the number of elements and the time taken to sort them.

Here is an example of what I mean.

Any help about how to go about calculating the Big O notation of something like this? Thanks!

Upvotes: 0

Views: 275

Answers (1)

Andrew
Andrew

Reputation: 14447

By definition, the asymptotic complexity of an algorithm represents is rate of growth (in time, space, or some other resource) as the size of the input(s) increase(s). It's best to analyze the algorithm itself to determine this rate of growth. However, if all you have is a "black box" sorting algorithm, and you only know the size of the input and the resulting time, the best you can do is to check whether a graph of inputs vs. time appears to grow in the pattern that a particular function would.

To test this idea, graph functions like:

  • f(n) = n
  • f(n) = n ln n
  • f(n) = n^2

etc., and see which most resembles the graph you created of the time to run the algorithm. Remember that asymptotic analysis ends up omitting both constant factors on each term and any lower-order terms. So, if your algorithm is still running in linear time even though the graph looks like f(n) = 2n, you still have an O(n) algorithm.

Upvotes: 2

Related Questions