Question

Write a report on Big O Concept and Analysis .For this report you will need to...

Write a report on Big O Concept and Analysis .For this report you will need to provide a formal definition of Big O and examine the various possible Big O values. Please use snippets of code, graphs and mathematical proofs to explain your understanding of this concept.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Report on Big O Concept and Analysis

Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity. It characterizes functions according to their growth rates: different functions with the same growth rate may be represented using the same O notation.

Here is the formal mathematical definition of Big O.

Let T(n) and f(n) be two positive functions. We write T(n) ∊ O(f(n)) and say that T(n) has an order of f(n), if there are positive constants M and n₀ such that T(n) ≤ M·f(n) for all n ≥ n₀.

Various Possible values of Big O

1 - A logarithmic algorithm – O(logn)
Runtime grows logarithmically in proportion to n

2- A linear algorithm – O(n)
Runtime grows directly in proportion to n.

3- A superlinear algorithm – O(nlogn)
Runtime grows in proportion to n.

4- A polynomial algorithm – O(nc)
Runtime grows quicker than previous all based on n.

5- A exponential algorithm – O(cn)
Runtime grows even faster than a polynomial algorithm based on n.

6- A factorial algorithm – O(n!)
Runtime grows the fastest and becomes quickly unusable for even
small values of n.

Graph Showing Different Function.

Let's have some code to understand Big O.

public static void printFirstItem(int[] items) {
    System.out.println(items[0]);
}

=> This method runs in O(1)O(1) time (or "constant time") relative to its input. The input array could be 1 item or 1,000 items, but this method would still just require one "step."

public static void printAllItems(int[] items) {
    for (int item : items) {
        System.out.println(item);
    }
}

=>This method runs in O(n)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 1,000 items, we have to print 1,000 times.

public static void printAllPossibleOrderedPairs(int[] items) {
    for (int firstItem : items) {
        for (int secondItem : items) {
            System.out.println(firstItem + ", " + secondItem);
        }
    }
}

=> Here 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 n^2 total prints. Thus this method runs in O(n^2) time (or "quadratic time"). If the array has 10 items, we have to print 100 times. If it has 1,000 items, we have to print 1,000,000 times.

Add a comment
Know the answer?
Add Answer to:
Write a report on Big O Concept and Analysis .For this report you will need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT