Just wanted to know, for example in the wikipedia page Dijkstra's algorithm what the absolute value bars meant in O(|E| + |V|log|V|)
Asked
Active
Viewed 2,684 times
7

William Rookwood
- 297
- 3
- 15
-
sizeof ............... – Mitch Wheat Feb 23 '13 at 06:14
1 Answers
7
The vertical bars indicate the cardinality (or size) of a set. In the case of Dijkstra's algorithm, |E|
is the number of edges and |V|
is the number of vertices.

Blckknght
- 100,903
- 11
- 120
- 169
-
2Why are these only used in graph theory? Cardinality just refers to the number of items in a set so why doesn't it apply to lists and arrays too? You never see O(|n|), but rather O(n). – Casey Hancock Aug 20 '17 at 03:25
-
1I don't think the premise is correct that vertical bars are exclusive to set theory. You also see them for other kinds of "size" in other contexts. For instance `|V|` is the magnitude of a vector `V`, and `|x|` is the absolute value of the number `x`. Those aren't quite the same as cardinality, but the concepts are pretty closely related. As for `O(n)`, usually `n` is already the size of some set, not the set itself. Formally it might be written as "`O(n)` for `n=|A|`" (if `A` is an array or other data structure). In informal contexts, people are often very sloppy about defining `n`. – Blckknght Dec 24 '17 at 03:29