有关运行时间的问题

编程入门 行业动态 更新时间:2024-10-25 00:37:12
本文介绍了有关运行时间的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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).

更多推荐

有关运行时间的问题

本文发布于:2023-11-15 23:21:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598862.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!