When something is Big O, does it mean that it is exactly the result of Big O?
up vote
0
down vote
favorite
When we say a method has the time complexity of O(n^2)
is it meant in the same way as in 10^2 = 100
or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?
algorithm big-o
|
show 4 more comments
up vote
0
down vote
favorite
When we say a method has the time complexity of O(n^2)
is it meant in the same way as in 10^2 = 100
or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?
algorithm big-o
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
2
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
3
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill theforall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
– Zabuza
Nov 10 at 16:54
|
show 4 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
When we say a method has the time complexity of O(n^2)
is it meant in the same way as in 10^2 = 100
or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?
algorithm big-o
When we say a method has the time complexity of O(n^2)
is it meant in the same way as in 10^2 = 100
or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?
algorithm big-o
algorithm big-o
asked Nov 10 at 15:56
user7722505
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
2
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
3
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill theforall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
– Zabuza
Nov 10 at 16:54
|
show 4 more comments
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
2
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
3
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill theforall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
– Zabuza
Nov 10 at 16:54
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
2
2
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
3
3
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the
forall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.– Zabuza
Nov 10 at 16:54
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the
forall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.– Zabuza
Nov 10 at 16:54
|
show 4 more comments
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Explanation
If a method f
is inside O(g)
, with g
being another function, it means that at some point (exist some n_0
such that for all n > n_0
) the function f
will always output a smaller value than g
for that point. However, g
is allowed to have an arbitrary constant k
. So f(n) <= k * g(n)
for all n
above some n_0
. So f
is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.
We say f
is asymptotically bounded by g
. Asymptotically means that we do not care how f
behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0
.
Illustration
An illustration would be this:
The blue function is k * g
with some constant k
, the red one is f
. We see that f
is greater at first, but then, starting at x_0
, it will always be smaller than k * g
. Thus f in O(g)
.
Definition
Mathematically, this can be expressed by
which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0
on, the function f
must be smaller than k * g
for all inputs. k
is allowed to be some constant.
Both images are taken from Wikipedia.
Examples
Here are a couple of examples to familiarize with the definition:
n
is inO(n)
(trivially)
n
is inO(n^2)
(trivially)
5n
is inO(n^2)
(starting fromn_0 = 5
)
25n^2
is inO(n^2)
(takingk = 25
or greater)
2n^2 + 4n + 6
is inO(n^2)
(takek = 3
, starting fromn_0 = 5
)
Notes
Actually,O(g)
is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g
).
So, although some authors write f = O(g)
, it is actually wrong and should be f in O(g)
.
There are also other, similar, sets, which only differ in the direction of the bound:
- Big-O: less equals
<=
- Small-o: less
<
- Big-Omega: greater equals
>=
- Small-omega: greater
>
- Theta: Big-O and Big-Omega at the same time (equals)
add a comment |
up vote
3
down vote
If means that the running time is bounded above by N².
More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.
For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Explanation
If a method f
is inside O(g)
, with g
being another function, it means that at some point (exist some n_0
such that for all n > n_0
) the function f
will always output a smaller value than g
for that point. However, g
is allowed to have an arbitrary constant k
. So f(n) <= k * g(n)
for all n
above some n_0
. So f
is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.
We say f
is asymptotically bounded by g
. Asymptotically means that we do not care how f
behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0
.
Illustration
An illustration would be this:
The blue function is k * g
with some constant k
, the red one is f
. We see that f
is greater at first, but then, starting at x_0
, it will always be smaller than k * g
. Thus f in O(g)
.
Definition
Mathematically, this can be expressed by
which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0
on, the function f
must be smaller than k * g
for all inputs. k
is allowed to be some constant.
Both images are taken from Wikipedia.
Examples
Here are a couple of examples to familiarize with the definition:
n
is inO(n)
(trivially)
n
is inO(n^2)
(trivially)
5n
is inO(n^2)
(starting fromn_0 = 5
)
25n^2
is inO(n^2)
(takingk = 25
or greater)
2n^2 + 4n + 6
is inO(n^2)
(takek = 3
, starting fromn_0 = 5
)
Notes
Actually,O(g)
is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g
).
So, although some authors write f = O(g)
, it is actually wrong and should be f in O(g)
.
There are also other, similar, sets, which only differ in the direction of the bound:
- Big-O: less equals
<=
- Small-o: less
<
- Big-Omega: greater equals
>=
- Small-omega: greater
>
- Theta: Big-O and Big-Omega at the same time (equals)
add a comment |
up vote
1
down vote
accepted
Explanation
If a method f
is inside O(g)
, with g
being another function, it means that at some point (exist some n_0
such that for all n > n_0
) the function f
will always output a smaller value than g
for that point. However, g
is allowed to have an arbitrary constant k
. So f(n) <= k * g(n)
for all n
above some n_0
. So f
is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.
We say f
is asymptotically bounded by g
. Asymptotically means that we do not care how f
behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0
.
Illustration
An illustration would be this:
The blue function is k * g
with some constant k
, the red one is f
. We see that f
is greater at first, but then, starting at x_0
, it will always be smaller than k * g
. Thus f in O(g)
.
Definition
Mathematically, this can be expressed by
which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0
on, the function f
must be smaller than k * g
for all inputs. k
is allowed to be some constant.
Both images are taken from Wikipedia.
Examples
Here are a couple of examples to familiarize with the definition:
n
is inO(n)
(trivially)
n
is inO(n^2)
(trivially)
5n
is inO(n^2)
(starting fromn_0 = 5
)
25n^2
is inO(n^2)
(takingk = 25
or greater)
2n^2 + 4n + 6
is inO(n^2)
(takek = 3
, starting fromn_0 = 5
)
Notes
Actually,O(g)
is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g
).
So, although some authors write f = O(g)
, it is actually wrong and should be f in O(g)
.
There are also other, similar, sets, which only differ in the direction of the bound:
- Big-O: less equals
<=
- Small-o: less
<
- Big-Omega: greater equals
>=
- Small-omega: greater
>
- Theta: Big-O and Big-Omega at the same time (equals)
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Explanation
If a method f
is inside O(g)
, with g
being another function, it means that at some point (exist some n_0
such that for all n > n_0
) the function f
will always output a smaller value than g
for that point. However, g
is allowed to have an arbitrary constant k
. So f(n) <= k * g(n)
for all n
above some n_0
. So f
is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.
We say f
is asymptotically bounded by g
. Asymptotically means that we do not care how f
behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0
.
Illustration
An illustration would be this:
The blue function is k * g
with some constant k
, the red one is f
. We see that f
is greater at first, but then, starting at x_0
, it will always be smaller than k * g
. Thus f in O(g)
.
Definition
Mathematically, this can be expressed by
which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0
on, the function f
must be smaller than k * g
for all inputs. k
is allowed to be some constant.
Both images are taken from Wikipedia.
Examples
Here are a couple of examples to familiarize with the definition:
n
is inO(n)
(trivially)
n
is inO(n^2)
(trivially)
5n
is inO(n^2)
(starting fromn_0 = 5
)
25n^2
is inO(n^2)
(takingk = 25
or greater)
2n^2 + 4n + 6
is inO(n^2)
(takek = 3
, starting fromn_0 = 5
)
Notes
Actually,O(g)
is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g
).
So, although some authors write f = O(g)
, it is actually wrong and should be f in O(g)
.
There are also other, similar, sets, which only differ in the direction of the bound:
- Big-O: less equals
<=
- Small-o: less
<
- Big-Omega: greater equals
>=
- Small-omega: greater
>
- Theta: Big-O and Big-Omega at the same time (equals)
Explanation
If a method f
is inside O(g)
, with g
being another function, it means that at some point (exist some n_0
such that for all n > n_0
) the function f
will always output a smaller value than g
for that point. However, g
is allowed to have an arbitrary constant k
. So f(n) <= k * g(n)
for all n
above some n_0
. So f
is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.
We say f
is asymptotically bounded by g
. Asymptotically means that we do not care how f
behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0
.
Illustration
An illustration would be this:
The blue function is k * g
with some constant k
, the red one is f
. We see that f
is greater at first, but then, starting at x_0
, it will always be smaller than k * g
. Thus f in O(g)
.
Definition
Mathematically, this can be expressed by
which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0
on, the function f
must be smaller than k * g
for all inputs. k
is allowed to be some constant.
Both images are taken from Wikipedia.
Examples
Here are a couple of examples to familiarize with the definition:
n
is inO(n)
(trivially)
n
is inO(n^2)
(trivially)
5n
is inO(n^2)
(starting fromn_0 = 5
)
25n^2
is inO(n^2)
(takingk = 25
or greater)
2n^2 + 4n + 6
is inO(n^2)
(takek = 3
, starting fromn_0 = 5
)
Notes
Actually,O(g)
is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g
).
So, although some authors write f = O(g)
, it is actually wrong and should be f in O(g)
.
There are also other, similar, sets, which only differ in the direction of the bound:
- Big-O: less equals
<=
- Small-o: less
<
- Big-Omega: greater equals
>=
- Small-omega: greater
>
- Theta: Big-O and Big-Omega at the same time (equals)
edited Nov 10 at 17:03
answered Nov 10 at 16:39
Zabuza
11k52538
11k52538
add a comment |
add a comment |
up vote
3
down vote
If means that the running time is bounded above by N².
More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.
For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.
add a comment |
up vote
3
down vote
If means that the running time is bounded above by N².
More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.
For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.
add a comment |
up vote
3
down vote
up vote
3
down vote
If means that the running time is bounded above by N².
More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.
For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.
If means that the running time is bounded above by N².
More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.
For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.
answered Nov 10 at 16:01
Yves Daoust
36k72558
36k72558
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240689%2fwhen-something-is-big-o-does-it-mean-that-it-is-exactly-the-result-of-big-o%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01
Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08
2
I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10
3
Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39
@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the
forall
operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.– Zabuza
Nov 10 at 16:54