An example of an O(2n) function is the recursive calculation of Fibonacci numbers. O(2n) denotes an algorithm whose growth doubles with each addition to the input data set. The growth curve of an O(2n) function is exponential - starting off very shallow, then rising meteorically.This function runs in O(n) time (or "linear time"), where n is the number of items in the array.
If the array has 10 items, we have to print 10 times. If it has 1000 items, we have to print 1000 timesHere we're nesting two loops. If our array has n items, our outer loop runs n times and our inner loop runs n times for each iteration of the outer loop, giving us n2 total prints.
Thus this function runs in O(n2) time (or "quadratic time"). If the array has 10 items, we have to print 100 times. If it has 1000 items, we have to print 1000000 times.An example of an O(2n) function is the recursive calculation of Fibonacci numbers. O(2n) denotes an algorithm whose growth doubles with each addition to the input data set.
The growth curve of an O(2n) function is exponential - starting off very shallow, then rising meteorically.When you're calculating the big O complexity of something, you just throw out the constantsThis is O(1 + n/2 + 100), which we just call O(n).
Why can we get away with this? Remember, for big O notation we're looking at what happens as n gets arbitrarily large. As n gets really big, adding 100 or dividing by 2 has a decreasingly significant effect.
O(n3 + 50n2 + 10000) is O(n3)O((n + 30) * (n + 5)) is O(n2)
Again, we can get away with this because the less significant terms quickly become, well, less significant as n gets big.
hope it helps you.....*_*