This draft deletes the entire topic.
Examples
-
Improvements requested by Pavneet Singh:
-
This example does not sufficiently illustrate the point and needs to be edited to provide more details. - Sep 16 at 8:13These example are all over the internet , a newbie won't be able to understand anything if he don't know how log n is computed so if to make this more clearer , these should be an explanation about logarithm functions with example to compute it instead of just number takingadd a comment
Unlike Big-O notation, which represents only upper bound of the running time for some algorithm, Big-Theta is a tight bound; both upper and lower bound. Tight bound is more precise, but also more difficult to compute.
The Big-Theta notation is symmetric:
f(x) = Ө(g(x)) <=> g(x) = Ө(f(x))
An intuitive way to grasp it is that
f(x) = Ө(g(x))
means that the graphs of f(x) and g(x) grow in the same rate, or that the graphs 'behave' similarly for big enough values of x.An example
If the algorithm for the input
n
takes42n^2 + 25n + 4
operations to finish, we say that isO(n^2)
, but is alsoO(n^3)
andO(n^100)
. However, it isӨ(n^2)
and it is notӨ(n^3)
,Ө(n^4)
etc. Algorithm that isӨ(f(n))
is alsoO(f(n))
, but not vice versa!Formal mathematical definition
Ө(g(x))
is a set of functions.Ө(g(x)) = {f(x) such that there exist positive constants c1, c2, N such that 0 <= c1*g(x) <= f(x) <= c2*g(x) for all x > N}
Because
Ө(g(x))
is a set, we could writef(x) ∈ Ө(g(x))
to indicate thatf(x)
is a member ofӨ(g(x))
. Instead, we will usually writef(x) = Ө(g(x))
to express the same notion - that's the common way.Whenever
Ө(g(x))
appears in a formula, we interpret it as standing for some anonymous function that we do not care to name. For example the equationT(n) = T(n/2) + Ө(n)
, meansT(n) = T(n/2) + f(n)
wheref(n)
is a function in the setӨ(n)
.Let
f
andg
be two functions defined on some subset of the real numbers. We writef(x) = Ө(g(x))
asx->infinity
if and only if there are positive constantsK
andL
and a real numberx0
such that holds:K|g(x)| <= f(x) <= L|g(x)|
for allx >= x0
.The definition is equal to:
f(x) = O(g(x)) and f(x) = Ω(g(x))
A method that uses limits
if
limit(x->infinity) f(x)/g(x) = c ∈ (0,∞)
i.e. the limit exists and it's positive, thenf(x) = Ө(g(x))
Common Complexity Classes
Name Notation n = 10 n = 100 Constant Ө(1) 1 1 Logarithmic Ө(log(n)) 3 7 Linear Ө(n) 10 100 Linearithmic Ө(n*log(n)) 30 700 Quadratic Ө(n^2) 100 10 000 Exponential Ө(2^n) 1 024 1.267650e+ 30 Factorial Ө(n!) 3 628 800 9.332622e+157 -
-
Let
f(n)
andg(n)
be two functions defined on the set of the positive real numbers,c, c1, c2, n0
are positive real constants.The asymptotic notations can be represented on a Venn diagram as follows:
Links
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. Introduction to Algorithms.
-
-
Ω-notation is used for asymptotic lower bound.
Formal definition
Let
f(n)
andg(n)
be two functions defined on the set of the positive real numbers. We writef(n) = Ω(g(n))
if there are positive constantsc
andn0
such that:0 ≤ c g(n) ≤ f(n) for all n ≥ n0
.Notes
f(n) = Ω(g(n))
means thatf(n)
grows asymptotically no slower thang(n)
. Also we can say aboutΩ(g(n))
when algorithm analysis is not enough for statement aboutΘ(g(n))
or / andO(g(n))
.From the definitions of notations follows the theorem:
For two any functions
f(n)
andg(n)
we havef(n) = Ө(g(n))
if and only iff(n) = O(g(n)) and f(n) = Ω(g(n))
.Graphically Ω-notation may be represented as follows:
For example lets we have
f(n) = 3n^2 + 5n - 4
. Thenf(n) = Ω(n^2)
. It is also correctf(n) = Ω(n)
, or evenf(n) = Ω(1)
.References
Formal definition and theorem are taken from the book "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein. Introduction to Algorithms".
Remarks
All algorithms are a list of steps to solve a problem. Each step has dependencies on some set of previous steps, or the start of the algorithm. A small problem might look like the following:
This structure is called a directed acyclic graph, or DAG for short. The links between each node in the graph represent dependencies in the order of operations, and there are no cycles in the graph.
How do dependencies happen? Take for example the following code:
total = 0
for(i = 1; i < 10; i++)
total = total + i
In this psuedocode, each iteration of the for loop is dependent on the result from the previous iteration because we are using the value calculated in the previous iteration in this next iteration. The DAG for this code might look like this:
If you understand this representation of algorithms, you can use it to understand algorithm complexity in terms of work and span.
Work
Work is the actual number of operations that need to be executed in order to achieve the goal of the algorithm for a given input size n
.
Span
Span is sometimes referred to as the critical path, and is the fewest number of steps an algorithm must make in order to achieve the goal of the algorithm.
The following image highlights the graph to show the differences between work and span on our sample DAG.
The work is the number of nodes in the graph as a whole. This is represented by the graph on the left above. The span is the critical path, or longest path from the start to the end. When work can be done in parallel, the yellow highlighted nodes on the right represent span, the fewest number of steps required. When work must be done serially, the span is the same as the work.
Both work and span can be evaluated independently in terms of analysis. The speed of an algorithm is determined by the span. The amount of computational power required is determined by the work.
Topic Outline
Sign up or log in
Save edit as a guest
Join Stack Overflow
Using Google
Using Facebook
Using Email and Password
We recognize you from another Stack Exchange Network site!
Join and Save Draft