Big O Notation with Absolute Value?

北慕城南 提交于 2019-12-01 04:35:22

问题


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)?


回答1:


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




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!