algorithm complexity - what double star means

大城市里の小女人 提交于 2019-12-22 08:14:37

问题


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.



来源:https://stackoverflow.com/questions/27458446/algorithm-complexity-what-double-star-means

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