patternMinor
Analysis of algorithms, 'big O' question
Viewed 0 times
biganalysisquestionalgorithms
Problem
The main question is, how exactly is the big O analysis calculated on routines? Is there a specific formula that relates what each function in a program does to a big O calculation?
Also, what about more complex iterations, such as colour conversions etc?
I would like to point out that this is not a homework question, rather, it is a question from my own research/programming learning curve. I have code that I am working on, but would like to know how this analysis is carried out.
Also, what about more complex iterations, such as colour conversions etc?
I would like to point out that this is not a homework question, rather, it is a question from my own research/programming learning curve. I have code that I am working on, but would like to know how this analysis is carried out.
Solution
There is no such formula. If there were, it would solve the halting problem, because we could take an algorithm (Turing machine), find its big-$\Theta$ complexity, then return true or false depending on if it was $\Theta (\infty)$.
For Big-O (upper bounds), there's technically a formula, since all functions are in $O(\infty)$. However, there's no way to find a tight upper bound, nor to test if an algorithm has a bound tighter than $O(\infty)$.
That said, there are certainly tools and heuristics for determining these things, as well as limited models of computation for which the problem is decidable.
For example, if you can express your routine using recursion, often you can find a recurrence relation for the running time, which you can solve to find the Big-O time. However, none of these techniques will work all the time.
For Big-O (upper bounds), there's technically a formula, since all functions are in $O(\infty)$. However, there's no way to find a tight upper bound, nor to test if an algorithm has a bound tighter than $O(\infty)$.
That said, there are certainly tools and heuristics for determining these things, as well as limited models of computation for which the problem is decidable.
For example, if you can express your routine using recursion, often you can find a recurrence relation for the running time, which you can solve to find the Big-O time. However, none of these techniques will work all the time.
Context
StackExchange Computer Science Q#12899, answer score: 3
Revisions (0)
No revisions yet.