What Is the Efficiency of Combining Different Algorithm Complexities?

  • Thread starter Thread starter surfy2455
  • Start date Start date
  • Tags Tags
    Algorithms
AI Thread Summary
The discussion revolves around determining the efficiency of a combined algorithm with complexities 200n, 3n^2, and 2^n-1. A proposed solution suggests combining these complexities through logarithmic manipulation, resulting in an efficiency of O(3log(n)). However, there is skepticism regarding the validity of this approach, particularly in the method of adding different algorithm complexities. An alternative perspective emphasizes selecting the most efficient algorithm based on the value of n to minimize run time. The conversation concludes with a suggestion to analyze the specific ranges of n for which each algorithm performs best.
surfy2455
Messages
3
Reaction score
0
*solved

Homework Statement



Lets say we have three algorithms, which include the following complexities 200n, 3n^2, 2^n-1. What would be a combined algorithm which is efficient?

Homework Equations


The Attempt at a Solution



Let me know if I'm on the right path here.

100n+3n^2 + 2^(n-1)
=log(100n)+log(3n^2)+log(2^(n-1))
=[log(100) + log(n)]+[log(3)+log(n^2)]+[(n-1)*log(2)]
=[log(100) + log(n)]+log(n^2)+(n-1),exclude constants
=log(n)+2log(n)+n
=(3log(n)+n)

The efficiency of the combined algorithm is O(3log(n)).
 
Last edited by a moderator:
Physics news on Phys.org
surfy2455 said:

Homework Statement



Lets say we have three algorithms, which include the following complexities 200n, 3n^2, 2^n-1. What would be a combined algorithm which is efficient?

Homework Equations





The Attempt at a Solution



Let me know if I'm on the right path here.

100n+3n^2 + 2^(n-1)
=log(100n)+log(3n^2)+log(2^(n-1))
=[log(100) + log(n)]+[log(3)+log(n^2)]+[(n-1)*log(2)]
=[log(100) + log(n)]+log(n^2)+(n-1),exclude constants
=log(n)+2log(n)+n
=(3log(n)+n)

The efficiency of the combined algorithm is O(3log(n)).

I'm not sure about the logic behind your derivation. Adding together the Orders of different algorithms doesn't make sense to me. Also, in the second line, why have you taken term-by-term logs? The second line won't equal the first.

I could be wrong, but when I look at the problem as stated I imagine that the idea would be to have the program select, based upon the value of n, the algorithm which would minimize the run time. Then you would have different complexities for different ranges of n. The problem would then be to work out the ranges of n that suit each algorithm.
 
gneill said:
I could be wrong, but when I look at the problem as stated I imagine that the idea would be to have the program select, based upon the value of n, the algorithm which would minimize the run time.

I think it is asking for what values of N is Alg(X) the fastest.

Naively, for what values of n (n>=0) is alg(1) < alg(2), alg(2)<alg(1), alg(2)<alg(3), alg (3)<alg(2), alg(3)<alg(1), alg(1)<alg3).
Then just select the best minima.

Starting with, for what vales of n does 200n - 3n^2 = 0
 
surfy2455 said:
*solved

thread can be deleted.

We don't ordinarily delete the contents of threads when they're solved. Other people can sometimes benefit from them.
 
Back
Top