algorithm complexity - what double star means

2019-05-05 18:54发布

问题:

Does anybody know what means doubled-star in complexity algorithm like this O(N**3)? I found that one in PHP's similar_text() function and do not understand it.

thx

回答1:

** means power. Hence, n**3 means n^3. Complexity is of the order n^3 or O(n^3)



回答2:

This double star is the exponentiation operator in PHP(^ operator in general for exponentiation).

As per PHP manual,

$a ** $b ---- Exponentiation Operator   
Result of raising $a to the $b'th power. Introduced in PHP 5.6.

hence, here the complexity is O(n^3),i.e., O of (n raised to power 3) OR cubic complexity.



回答3:

It's not always easy to write mathematics when you're only allowed ASCII, so often writers resort to using operators found in programming languages as a way of concisely representing the mathematics.

In some languages, ** means exponentiation, and this is what it means here. ASCII doesn't have a superscript, so it's impossible to represent exponentiation in standard mathematical notation if you're restricted to ASCII. The fact that you found this in a PHP context is a further clue, since PHP is one of the languages that uses ** for exponentiation.

O(n**3) means O(n3).



回答4:

** star is short hand for raise to power(and also a valid operator in some languages). This is the same as N^3. Thus the function has cubic complexity.