I'm going through some programming interview question books, and I've seen reference to "O(|A|)"
time complexity. I've never seen this notation with the absolute value given.
Some research led me to Big O Cheatsheet that references this notation under the graphs section. The problem I'm researching is about partitioning an array, which isn't really a graph question (though I risk perhaps showing my ignorance with that statement).
Does |A|
refer to the magnitude of the array, or otherwise number of elements, i.e. O(N)
?
In set theory notation |A|
is the cardinality of set A
, in other words the number of elements contained in set A
.
For Reference: http://www.mathsisfun.com/sets/symbols.html
You will see this notation always when A
is not a number.
A
could be many things, so |A|
depends on the context. E.g.
A
is a vector of a lattice, so|A|
is the length of the vector.A
is an (maybe unknown) algorithm (e.g. an attacker to an encryption), then|A|
could be the complexity of this algorithm or the length of the random bit vector this algorithm uses.A
is a set, then is|A|
the number of elements in the set, as Kostub Deshmukh mentioned.
There can be many more cases.
来源:https://stackoverflow.com/questions/30960065/big-o-notation-with-absolute-value