简体   繁体   English

插入多集的运行时

[英]Runtime of inserting into multi set

What is the overall runtime of inserting into a multi set, lets say I am going over a billion elements and inserting into multi-set, which maintains a sorted ordering. 插入多集的总体运行时间是多少,可以说我要遍历十亿个元素,然后插入多集,这将保持排序的顺序。 What is my worst case runtime? 我最坏的情况是什么?

According to http://www.sgi.com/tech/stl/MultipleAssociativeContainer.html the complexity of insert is O(log n) for inserting a single element; 根据http://www.sgi.com/tech/stl/MultipleAssociativeContainer.html ,插入单个元素的复杂度为O(log n); for inserting a sequence of length N, it is O(N log n). 对于插入长度为N的序列,它为O(N log n)。

If you really want the time, and not the asymptotic complexity, you can time it for a different values - 1000, 10,000 - say, and then compute the constants of proportionality from there. 如果您确实想要时间而不是渐近复杂度,则可以将其计时为其他值(例如1000、10,000),然后从那里计算比例常数。 The actual equation will be t = A n log n + C. 实际方程为t = A n log n +C。

But of course the next time you run on different hardware the values of A and C will change. 但是,当然,下次您在不同的硬件上运行时,A和C的值将更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM