Help finding Complexity in Big-O notation

In summary, the conversation discusses finding the complexity of an algorithm expressed as a sum and determining if it is bounded by n^3 or n^4. The first simplification step involves evaluating the innermost sum and using rules such as O(n)O(n)=O(n^2). The conversation also mentions plotting the algorithm against n^3 and considering n^4 as a possible boundary. It is suggested that the complexity is likely O(n^4) and easy to show.
  • #1
pandrade
4
0

Homework Statement



I have found the complexity of an algorithm as the expression below. How can I find the complexity in big O notation for such expression? Or proved that it's bounded by [tex] n^3 [/tex]or [tex] n^4 [/tex] ? Thank you!

Homework Equations



[tex] \sum_{j=3}^{n} \left[(j-1)[2(j-2)-1] + \sum_{i=2}^{j-2}(i) +
\sum_{k=2}^{j-2}\left[k(j-(k+1))+\sum_{i=k}^{j-2}(i)\right]\right] [/tex]

The Attempt at a Solution



I run 1000 numbers and apparently it is bounded by [tex] n^3 [/tex].
 
Last edited by a moderator:
Physics news on Phys.org
  • #2
First simplification step:
[tex] \sum_{j=3}^{n} \left[O(n)O(n) + O(n^2) +
\sum_{k=2}^{j-2}\left[k(j-(k+1))+\sum_{i=k}^{j-2}(i)\right]\right] [/tex]
To get O(n^3) I think you have to evaluate the innermost sum to cancel some parts of the k(j-(k+1)), but apart from that (or for an O(n^4)-boundary) you can always estimate those terms as bounded by n, with rules like O(n)O(n)=O(n^2) and so on.
 
  • #3
I see.
To be honest I would like to get a [tex] n^3 [/tex] :-), but I see what you are saying.
I have plotted it against [tex] n^3 [/tex] for [tex] n [/tex] from 1 to 10,000 and I guess I got carried away because it seemed to be asymptotically bounded, but of course, there's no guarantee, at all.
I will try to open the sum and see if it cancels out, as you suggested, if not, I'll consider [tex] n^4 [/tex].
Thank you so much!
 
  • #4
I don't think this is O(n^3).
I would expect O(n^4), and this is easy to show.
 
  • #5


In order to find the complexity in big O notation, we need to analyze the expression and determine its highest order term. In this case, we can see that the highest order term is n^3, as it is the term with the largest exponent. Therefore, the complexity in big O notation would be O(n^3).

To prove that the expression is bounded by n^3, we can use the definition of big O notation which states that a function f(n) is bounded by g(n) if there exists a constant c and a value n0 such that f(n) <= c*g(n) for all n>n0. In this case, we can set c=1 and n0=1, and we can see that for all values of n greater than 1, the expression given will always be less than or equal to n^3. Therefore, we can conclude that the expression is bounded by n^3.
 

Related to Help finding Complexity in Big-O notation

What is Big-O notation and why is it important in computer science?

Big-O notation is a mathematical notation used to describe the complexity of an algorithm, or how the runtime of an algorithm changes as the size of the input increases. It is important in computer science because it allows us to analyze and compare the efficiency of different algorithms, and make informed decisions about which algorithm to use in a given situation.

How do I determine the complexity of an algorithm using Big-O notation?

To determine the complexity of an algorithm, you need to look at how the runtime of the algorithm changes as the input size increases. This can be done by counting the number of basic operations (such as comparisons or assignments) that the algorithm performs in the worst-case scenario. The number of operations will give you the Big-O complexity of the algorithm.

What are the common complexities seen in Big-O notation?

The most common complexities seen in Big-O notation are O(1) (constant), O(log n) (logarithmic), O(n) (linear), O(n log n) (linearithmic), O(n^2) (quadratic), O(n^3) (cubic), and O(2^n) (exponential). These complexities represent different rates at which the runtime of an algorithm increases as the input size increases.

How does the choice of data structure affect the complexity of an algorithm?

The choice of data structure can greatly affect the complexity of an algorithm. For example, using a hash table can lead to constant time lookups, resulting in an O(1) complexity, while using a linear search in an unsorted array can result in an O(n) complexity. It is important to choose the most efficient data structure for a given algorithm in order to achieve the best possible runtime complexity.

What are some tips for optimizing an algorithm's complexity?

Some tips for optimizing an algorithm's complexity include using efficient data structures, reducing the number of nested loops, and avoiding unnecessary operations. It can also be helpful to break down a complex algorithm into smaller, simpler steps and analyze the complexity of each step individually. Additionally, considering alternative algorithms and choosing the one with the best complexity can also lead to optimization.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
987
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
11
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
878
  • Engineering and Comp Sci Homework Help
Replies
26
Views
3K
  • Advanced Physics Homework Help
Replies
1
Views
874
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Back
Top