有关运行时间的问题 [英] Questions About Running time
本文介绍了有关运行时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
big-O表示法中的运行时间是什么:
vector.push_back(item)
和
vec.erase(itr)// itr指向向量中间
解决方案 O(1)发生),以防 push_back()
O(n)。 erase()
即线性元素的数量被消除(析构函数)在最后一个元素删除(移动)后。
What is the running time in big-O notation of:
vector.push_back(item)
and
vec.erase(itr) // itr points in the middle of a vector
解决方案 O(1) (amortized time, reallocation may happen) in case of push_back()
O(n) in case of erase()
i.e Linear on the number of elements erased (destructors) plus the number of elements after the last element deleted (moving).
这篇关于有关运行时间的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文