0

I am looking at code to find complexity of deep first search (DFS). How does O(|V| + |E|) differ from O(V+E). What is the meaning of |·| around V and E? Does it mean the "sum of all vertices" is represented as |V| ?

usr1234567
  • 21,601
  • 16
  • 108
  • 128
JavaDeveloper
  • 5,320
  • 16
  • 79
  • 132

2 Answers2

1

V and E are a sets. So O(E) would be undefined. |·| gives you the number of elements in the set, it's called cardinality in Maths. For a graph G = (V,E) |E| is the number of edges, |V| is the number of vertices.

When people write O(V+E) they actually mean O(|V| + |E|) and most readers will understand it that way, because it is the only plausible explanation. Still it is unclean and I would not use it myself.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
0

|V| typically means the cardinality (number of elements) in V. So O(|V| + |E|) means "on the order of the number of elements in V plus the number of elements in E."

Nick Bailey
  • 3,078
  • 2
  • 11
  • 13