简体   繁体   English

std::unordered_set 或 std::unordered_map 中 std::find() 的时间复杂度,没有冲突

[英]Time complexity of std::find() in std::unordered_set or std::unordered_map with no collisions

I know unordered_map has O(1) lookups but std::find() is a searching algorithm(I guess) in other containers.So is it O(1) or O(n) considering there is no collision.我知道 unordered_map 有 O(1) 查找,但 std::find() 是其他容器中的搜索算法(我猜)。考虑到没有冲突,它是 O(1) 还是 O(n)。

From cppreference for std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::find :来自std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::findcppreference

Complexity复杂

Constant on average, worst case linear in the size of the container.平均恒定,最坏情况与容器大小呈线性关系。

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

相关问题 std :: unordered_set的std :: unordered_map外立面-如何? - A std::unordered_map facade for a std::unordered_set - how? KeyEqual在std :: unordered_set / std :: unordered_map中的用处 - Usefulness of KeyEqual in std::unordered_set/std::unordered_map 何时应在 std::unordered_map/std::unordered_set 上使用 std::map/std::set? - When std::map/std::set should be used over std::unordered_map/std::unordered_set? 使用boost序列化std :: unordered_map <int,std :: unordered_set <int >> - serialize std::unordered_map < int, std::unordered_set<int> > with boost 预测 std::unordered_set 或 std::unordered_map 的调整大小/重新哈希 - Predict resize/rehash of std::unordered_set or std::unordered_map std :: unordered_set :: erase复杂性 - std::unordered_set::erase complexity std :: unordered_set迭代器遍历的复杂性 - Complexity of std::unordered_set iterator traversal C ++ std :: unordered_map复杂度 - C++ std::unordered_map complexity 为什么 std::set / std::map 和 std::unordered_set / std::unordered_map 没有 std::erase 重载但有 std::erase_if? - Why std::set / std::map and std::unordered_set / std::unordered_map does NOT have std::erase overload but have std::erase_if? 迭代期间添加到 std::unordered_set(或 unordered_map)中的元素是否会在迭代期间被访问? - Will elements added into a std::unordered_set (or unordered_map) during iteration be visited during the iterations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM