O(nk)和O(n + k)在时间复杂度上有什么区别? [英] what is the difference between O(nk) and O(n+k) in time complexity?
本文介绍了O(nk)和O(n + k)在时间复杂度上有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在算法分析中时间复杂度的大O表示法中,当算法依赖于n和k时,这两种表示法之间的区别是什么。
如果存在嵌套循环且外部循环运行n次且内部循环运行k次,还可以提供符号帮助吗?
In big O notation of time complexity in algorithmic analysis, when an algorithm depends on n and k, what is the difference between these two notations. Also pls help in the notation to use if there is a nested loop with outer loop running n times and inner loop running k times ?
推荐答案
O(nk):
for( i=0; i<n; i++ ) {
for( j=0; j<k; j++ )
{}
}
O(n + k):
for( i=0; i<n; i++ )
{}
for( j=0; j<k; j++ )
{}
这篇关于O(nk)和O(n + k)在时间复杂度上有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文