本文介绍了有关运行时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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).
更多推荐
有关运行时间的问题
发布评论