Big-O notation

Let's assume that we have a f(n) method, which we want to represent with a time complexity function (that is, a Set) g(n):

f(n) is O(g(n)) if, and only if, there exists constants c and n0, where f(n) <= cg(n) and where the input size n >= n0.

Now, let's try to apply this to our previous example:

f(n) = Tdouble = C5 * n + C4 
f(n) = Tdouble = 4n + 1 // cause C5 and C4 can be any constants

For this example, we denoted it with the set O(n), that is, g(n) = n

For our time complexity assertion to hold, we will need to satisfy the following condition:

4n + 1 <= c * n , where n >= n0

This equation is satisfied for values c = 5 and n0 = 1. Also, since the definition is met, we can safely say that the f(n) function is big-O(g(n)), that is, O(g(n)) or, in this case, O(n). We can also see this when plotted on a graph, as shown in the following diagram; after the value of n = 1, we can see that the value of c * g(n) is always greater than f(n) asymptotically. Take a look at the following diagram:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.212.91